Announcement Announcement Module
Collapse
No announcement yet.
Request-reply confusion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Request-reply confusion

    Hi,

    I'm quite new to RabbitMQ (and AMQP).
    I'm trying to implement a rather simple communication between two processes, they exchange data in JSON format.
    I'm using convertSendAndReceive() for the producer and it works pretty well.
    But I'm having trouble with the consumer.
    What I'd like to do is to have a POJO having this structure :

    Code:
    public class Consumer {
        OutputObject handleRequest(InputObject obj) {
            // Handle the request represented as InputObject here and return an OutputObject as result.
        }
    }
    But I'm confused because even after having read the documentation I haven't found any class/method for doing this.

    Should I use plain RabbitTemplate on the consumer side, with receive() and then call send() on the getReplyTo() queue, which lead me to another question : I cannot send a message to a specific queue but has to go through an exchange and a routing key, so how do I send back my response without routing key ?

    I've read the documentation as well as the book "RabbitMQ in Action" but could not have an answer to this simple example of RPC.
    I've also looked at the spring-amqp source code but found nothing.

    I'm sure I've missed something. Can anyone point me to a clear answer to my problem ?

    Thanks.

  • #2
    There is an open JIRA to make this a little easier https://jira.springsource.org/browse/AMQP-72

    However, you can use the AMQP support in the Spring Integration project http://static.springsource.org/sprin...html/amqp.html - specifically the inbound gateway - to do this. It allows your code to be just a POJO.

    If you don't know, and don't want to learn Spring Integration, you can use a Rabbit Template on the receiving side too; you get the exchange and routing key from the replyTo header...

    Code:
    Address replyTo = message.getMessageProperties().getReplyToAddress();
    replyTo has getExchange() and getRoutingKey() methods.

    You can look at the code in the Spring Integration AmqpInboundGateway to see how he does it.
    Last edited by Gary Russell; Jul 24th, 2012, 09:06 PM.

    Comment


    • #3
      Thanks a lot Gary !

      Comment

      Working...
      X