You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by ENP <pr...@stc.donpac.ru> on 2006/06/15 11:53:22 UTC

Get message ID from producer.send(message)

Hi,

Is it possible to get AMQ-generated message ID after executing
producer.send(message) in any way?

It can be very useful to associate request with replay. Any other technique
require generating unique number (GUID?) and use it as custom message header
or name of temp topic :(
--
View this message in context: http://www.nabble.com/Get-message-ID-from-producer.send%28message%29-t1791249.html#a4880140
Sent from the ActiveMQ - User forum at Nabble.com.


Re: Get message ID from producer.send(message)

Posted by James Strachan <ja...@gmail.com>.
On 6/15/06, ENP <pr...@stc.donpac.ru> wrote:
>
> Hi,
>
> Is it possible to get AMQ-generated message ID after executing
> producer.send(message) in any way?

Yes - just access the Message.getJMSMessageID() after you've called send().


> It can be very useful to associate request with replay. Any other technique
> require generating unique number (GUID?) and use it as custom message header
> or name of temp topic :(

To correlate requests to responses you should use the JMSCorrelationID header.
http://incubator.apache.org/activemq/how-should-i-implement-request-response-with-jms.html

this allows you to attach the correlation ID to the message before its
sent; then services which process your message and reply with results
should attach the correlation ID from the request to any responses.

BTW if you are using a JMSReplyTo header for responses which the
client side uses a temporary queue, the correlation ID can just be an
incrementing long as a String. There's no need for it to be a full
GUID as the temporary queue acts as a GUID.

But if you really want a GUID then use this utility class...

http://incubator.apache.org/activemq/maven/activemq-core/apidocs/org/apache/activemq/util/IdGenerator.html

Unless you're on Java 5 in which case you can use...
http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html
-- 

James
-------
http://radio.weblogs.com/0112098/