Whereas the MessageHandler
interface provides the foundation for many of the
components that enable non-invasive invocation of your application code from the messaging
system, sometimes it is necessary to invoke the messaging system from your application
code. Spring Integration provides a RequestReplyTemplate
that supports a
variety of request-reply scenarios. For example, it is possible to send a request and wait for a reply.
RequestReplyTemplate template = new RequestReplyTemplate(requestChannel); Message reply = template.request(new StringMessage("test"));
In that example, a temporary anonymous channel would be used internally by the template. However, the 'replyChannel' may be configured explicitly in which case the template will manage the reply correlation.
RequestReplyTemplate template = new RequestReplyTemplate(requestChannel); template.setReplyChannel(replyChannel); Message reply = template.request(new StringMessage("test"));