1

I have a spring rabbit listener

@Override
public void onMessage(Message message, Channel channel) {
     //do something

      channel.basicPublish("",queue name, null, SerializationUtils.serialize(r));

}

How rabbit will understand that this response is for my particular message? In case if I have a thousands of messages. What I need to do to link request and response? And is there a way to pass to the channel POJO without serialization? Thanks

1 Answer 1

2

You should take care there about replyTo and correlation.

But I'd say that there is no reason to do that manually, because MessageListenerAdapter takes care about that.

You just need supply a POJO with request-reply capabilities:

class Delegate {
    @SuppressWarnings("unused")
    public String handleMessage(String input) {
        called.set(true);
        return "processed" + input;
    }
}

adapter.setDelegate(new Delegate());
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you ,so in other words, I need to send my object with boolean flag to the consumer, consumer sets this flag to true and pulls back, right? Should be this flag attribute be thread safe? Thanks
Sorry, I don't understand what you talk about. The POJO consumer (Delegate) is just responsible to get deal with domain object and knows nothing about AMQP (e.g. Channel). No need to send any boolean flag. Just send Message as is with desired body (template.convertSendAndReceive) and your POJO should accept the domain object as method argument and can return another domain. The MessageListenerAdapter will take care about conversions. SimpleMessageConverter is used by default.
Thanks, sorry but I was confused a bit because I did the same from the beginning: return new MessageListenerAdapter(orderSaverListener); So if I understood correctly, I should not care about corellationIDS and so on, and in this question description I should not do anything,right?
Looks like. At least it works that way in the SimpleMessageListenerContainer: docs.spring.io/spring-amqp/docs/latest-ga/reference/html/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.