1
votes

i have a typical spring-webmvc application (with REST request mapped in Controller's method that call a Service's method) and I would like to use spring-integration to manage the asynchronous functionality (e.g. mail, sms, notification...).

For example i would like that a Service Component after insert in my DB publish a message in spring-integration context channel in asycn mode so that the control return immediataly at the Controller to return an http response to the client.

How to integrate "spring-integration" in my existing spring-mvc application?

1

1 Answers

4
votes

Simply inject a Messaging Gateway into your controller. Define an interface, declare an <int:gateway id="toMail"/> and use normal Spring bean injection techniques to inject the gateway (as an instance of your interface) into the controller.

If you don't want to wait for a a reply; set the method return value to void and, if you make the first channel (the gateway's default-request-channel) an Executor Channel, the message will be handed off to another thread and the gateway will returm immediately. Configuring an Executor Channel.