0

I'm following the instructions for the Stock Trading sample, which outlines how to use request/reply messaging in spring-amqp: http://static.springsource.org/spring-amqp/docs/1.2.x/reference/html/sample-apps.html#d4e742

I've tweaked the sample instructions to create a client which should wait for the reply by using convertSendAndReceive instead of convertAndSend: https://gist.github.com/pulkitsinghal/5774487

Now even though the reply is put on the responseQueue and I've updated the timeout rabbitTemplate.setReplyTimeout(60000); to be longer than the 5 second default ... in my client I receive null back as the reply.

Does anyone know what's going on?


Update#1

I was advised to add a <reply-listener/> to the <rabbit:template/> but I'm not sure how to do that programatically:

@Bean
public RabbitTemplate rabbitTemplate() {
    RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
    rabbitTemplate.setMessageConverter(jsonMessageConverter());
    rabbitTemplate.setReplyQueue(responseQueue());
    rabbitTemplate.setReplyTimeout(60000);
    // following is private
    //rabbitTemplate.addListener
    return rabbitTemplate;
}
pinepain
  • 12,453
  • 3
  • 60
  • 65
pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84
  • I hope you aren't using spring 1.2. – Sotirios Delimanolis Jun 13 '13 at 15:26
  • I've tried both versions `1.1.4.RELEASE` and `1.2.0.BUILD-SNAPSHOT` for `org.springframework.amqp.spring-rabbit` ... but they both have the same behavior. – pulkitsinghal Jun 13 '13 at 15:36
  • I'm not trying to answer your question. Spring is at version 3.2.3 right now, you really shouldn't be using outdated libraries. – Sotirios Delimanolis Jun 13 '13 at 15:39
  • Yup I'm on `3.1.x` based on the dependency hierarchy for `spring-rabbit` and I've got no inclination to jump upto `3.2.3` without having a good reason to do so. I think the docs URL may have thrown you off ... the doc url captures the version # of `spring-rabbit` and not spring itself. – pulkitsinghal Jun 13 '13 at 15:49

1 Answers1

1

I assume the fact you are not getting an error on the convertsendAndReceive means that you have configured the RabbitTemplate with a fixed reply queue; if you do that, you need a listener container to receive the messages with the template as the 'listener'.

The easiest way to configure this is with xml

<rabbit:template ... reply-queue="foo">
    <reply-listener/>
</rabbit:template>

I suggest you get it working first without a fixed reply queue - let the template create its own reply queue.

You should also remove the MessagePostProcessor in the convertSendAndReceive because the template will take care of its own reply queue and correlation configuration. This is not allowed when there's not a fixed reply queue.

When you switch to using a fixed reply-queue I suggest you use 1.2.0.M1 (or snapshot) because the template used a non-standard correlation technique.

Update: To use @Bean configuration instead of XML simply create a SimpleMessageListenerContainer bean and make its listener the RabbitTemplate. Just be sure to use the same queue in both places (the parser takes care of that when using the namespace).

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Gary I started using `1.2.0.BUILD-SNAPSHOT` this morning ... but its super important to me that I get the response back where I've called `convertsendAndReceive` ... if I configure a `` then the MessageListenerAdapter will let the POJO which implements `handleMessage` take control of the flow ... which is nowhere around the code block that calls `convertsendAndReceive` ... or am I misunderstanding you? Is `` different from ``? – pulkitsinghal Jun 13 '13 at 17:33
  • Gary I'm staring at `TemplateParser` which configures `` off of the xml file on line 109 but for the life of me, I can't figure out how to do this programmatically in a `@Configuration` file instead of in the xml file ...could you please have a peek at the update in my answer and comment on this? – pulkitsinghal Jun 13 '13 at 18:14
  • 1
    You simply need to declare a `SimpleMessageListenerContainer` where the `messageListener` property is the `RabbitTemplate` that is to receive the replies. – Gary Russell Jun 13 '13 at 18:38
  • Thanks, I was a bit turned around, I thought I had to set a property on `RabbitTemplate` but now I understand that its the other way around. – pulkitsinghal Jun 13 '13 at 19:13
  • BTW neither having nor removing `MessagePostProcessor` in `convertSendAndReceive` made a difference in how the request/reply operated ... maybe because i have a fixed queue for responses ... so i took your advice and removed it alltogether. – pulkitsinghal Jun 13 '13 at 19:30
  • Since you seem to be part of the spring foundation, would you mind updating the docs Gary? http://static.springsource.org/spring-amqp/reference/html/amqp.html#request-reply could afford to give the `@Configuration` equivalent of the applicationContext.xml stuff. Here are my notes on this: https://gist.github.com/pulkitsinghal/5776671 – pulkitsinghal Jun 13 '13 at 19:36
  • 1
    Would you mind opening a 'Documentation' JIRA issue? https://jira.springsource.org/browse/AMQP – Gary Russell Jun 13 '13 at 19:56