PDA

View Full Version : Get JMSMessageID after Msg is handed over to native mqclient



thomas.darimont
Aug 23rd, 2005, 07:15 AM
Hello,

does anybody know whether there is a way, to get the JMSMessageID after the Message is handed over to the "native" JMS transfer mechanism (jbossmq client) by using the JMSTemplate?

At the time I use this ugly hack:



public void sendPrintRequestFor(final PrintJob printJob) {
//Ugly Hack to get the JMSMessageID
final Message[] messageContainer = new Message[1];
getJmsTemplate().convertAndSend(printJob, new MessagePostProcessor() {
public Message postProcessMessage(Message message)
throws JMSException {
messageContainer[0] = message;
return message;
}
});

try {
printJob.setJobID(messageContainer[0].getJMSMessag eID());
} catch (JMSException e) {
throw new IllegalStateException(e);
}
}


So long,
Thomas

Pieper
Feb 23rd, 2006, 07:14 AM
Hi all,

similar request to the "receive JMS message ID". (resp. JMSCorrelationID)

Is it possible to set the "JMSMessageID" (resp. JMSCorrelationID) value after sending with ConvertAndSend?


JmsTemplate is a good abstraction layer, but I think to get some features out of the Jms interface it needs some polishing, doesn't it?

Pieper

Pieper
Feb 23rd, 2006, 08:56 AM
Hi all,

got the solution. I've found it in the excellent "Professional Java Development with Spring" book:



public void sendStringWithId(String msg, String correlationId)
{
log.info("Start JMS template method for sending strings");

JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);

final String textMessage = msg;
final String corrId = correlationId;

log.debug("Text message: " + textMessage);
log.debug("CorrelationId: " + correlationId);

log.debug("Sending string with CorrelationId " + correlationId);
/*
* Callback method for sending JMS message with specific Correlation ID
*/
jmsTemplate.send(sendQueueName, new MessageCreator()
{

public Message createMessage(Session session) throws JMSException
{
Message m = session.createTextMessage(textMessage);
m.setJMSCorrelationID(corrId);
return m;
}
});

}




Pieper