PDA

View Full Version : Get message info in handleMessage class



ajdevries
Jul 5th, 2011, 02:49 PM
Hi,

I've made a working version in SpringMQ to communicate between Java and Ruby. Everything is working quite well. So compliments for that.

I'm using a MessageHandler class that has a

public ReturnObject handleMessage(RecieveObject object)
{
...
}

method.

The problem over here is when the message that is received and transformed misses a replyTo header, I'm getting an exception when return the response to the queue. After that the same message is handled again and I'm getting in an infinitive loop.

Is there some possibility to determine whether the received message contains a replyTo header, so I can act on this one?

Thanks.
AJ

Dave Syer
Jul 6th, 2011, 02:14 AM
You can get a reference to the whole Message in your handler, with all the headers and everything. Doing it that way would mean you'd have to do the conversion to ReceiveObject (sic) inside the handler. Or you could add the replyTo header to your ReceiveObject, and provide a MessageConverter that knows how to populate it (that would be my choice probably). Or you could extend the MessageListenerAdapter and extract the handler method arguments in any way you like.

ajdevries
Jul 6th, 2011, 02:21 AM
Hi Dave,

Thanks for your response. I think I will extend the MessageListenerAdapter to get grip on the Message, maybe a good feature anyway.

Thanks.
AJ

ajdevries
Jul 13th, 2011, 02:12 PM
I created a custom listener class with the possibility to set the message via a MessageHolder interface.

Maybe it is usefull to add this to the MessageListenerAdapter. Here is the code: 4068

Dave Syer
Jul 14th, 2011, 03:08 AM
Your approach looks dangerous because it is not thread safe. I will try and make it easier to use an override of buildListenerArguments() (https://jira.springsource.org/browse/AMQP-180).

Dave Syer
Jul 14th, 2011, 03:20 AM
...or maybe you could override handleResult() and get the behaviour you need (which I didn't really understand properly)?

ajdevries
Jul 14th, 2011, 04:22 AM
Okay, thanks for your response, I wasn't aware that the message handler isn't a prototype bean. The only thing I need to know is, contains the message a reply to property.

I can fix this on a different way. Thanks for you feedback!