Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springs integration's reply correlation process details

I can't find documentation for reply processing with gateways and service activators.

If I have gateway which: 1) sends requests to channel ReqChannel 2) accepts replies on channel RepChannel

ReqChannel is connected to router, that routes incoming messages to one of some service activators, let say AServiceActivator and BServiceActivator and that service activators have a configured output-channel="RepChannel".

And if I execute more than one method call on gateway's interface asynchronously or simultaneously from different threads, how gateway will correlate incoming replies to actual service caller?

like image 811
Mikhail Tsaplin Avatar asked Jul 28 '12 06:07

Mikhail Tsaplin


Video Answer


1 Answers

The gateway creates a temporary reply channel and puts it in the header of the message. This mechanism provides the necessary correlation because each message gets its own reply channel.

If the final consumer (say a service-activator) has no output-channel, the framework automatically sends the reply to the replyChannel header.

For this reason, it is generally not necessary to declare a reply-channel on the gateway for the final consumer to send to.

However, there are times when this is useful - such as if you want to wire-tap the reply channel, or make it a publish-subscribe channel, so the result goes to multiple places.

In this case (when there is a reply-channel on the gateway, and the final consumer sends a message there), the framework simply bridges the explicitly declared reply-channel to the temporary reply channel in the message header.

For this reason, it is critical to retain the replyChannel header in your flow. You can't send some arbitrary reply to a reply-channel, unless you include the original message's replyChannel header.

like image 102
Gary Russell Avatar answered Sep 24 '22 15:09

Gary Russell