Nav

To Listen For A Reply

Request/Reply is a very common pattern between applications, thus the new AMQP Connector provides an operation specially designed for that, called publish-consume. The publish-consume operation allows you to publish a Message to any exchange, and then wait for a reply on a different Destination.

When using this operation, the replyTo property of the outgoing Message will contain the id of the Queue on which our application will be waiting for a response. This destination may be a well-known destination, or it may be a temporary queue created on the fly with the only purpose of receiving a single response message.

Finally, the result of the operation will be the Message received as a response, with exactly the same structure as if a consume operation was invoked.

Waiting For A Reply On A Temporary Queue

Using a temporary Queue to wait for a response is very simple, just configure the message being sent and the operation will automatically wait for a response in a temporary Queue:


         
      
1
<amqp:publish-consume config-ref="config" exchangeName="targetExchange" maximumWait="20" maximumWaitUnit="SECONDS"/>

In this example, the operation will publish a Message with the current payload as its body and the replyTo property of the message configured to a temporary destination, to the targetExchange. Then, it will automatically try to consume the response from that temporary Queue until a Message is consumed or the maximumWait is reached (in which case it will fail with a AMQP:TIMEOUT error).

Receiving The Reply On A Known Queue

In many cases you don’t want reply queues to be created per-request basis, but instead a well-known Queue is used for replies. For this cases, all you have to do is configure the reply-to parameter on the outgoing Message:


         
      
1
2
3
4
5
<amqp:publish-consume config-ref="config" exchangeName="targetExchange">
    <amqp:message>
                    <amqp:properties reply-to="replyToQueue" />
    </amqp:message>
</amqp:publish-consume>

Now the operation will publish a Message to the targetExchange with the current payload as its body and the replyTo property configured with the replyToQueue. Then, it will automatically try to consume the response from the replyToQueue Queue until a Message is consumed or the maximumWait is reached (in which case it will fail with a AMQP:TIMEOUT error).

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.

+