Announcement Announcement Module
Collapse
No announcement yet.
Get JMSMessageID after Msg is handed over to native mqclient Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get JMSMessageID after Msg is handed over to native mqclient

    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:

    Code:
    			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].getJMSMessageID());
    		} catch (JMSException e) {
    			throw new IllegalStateException(e);
    		}
    	}
    So long,
    Thomas

  • #2
    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
    Last edited by Pieper; Feb 23rd, 2006, 07:54 AM.

    Comment


    • #3
      Hi all,

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

      Code:
       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

      Comment

      Working...
      X