Results 1 to 3 of 3

Thread: Get JMSMessageID after Msg is handed over to native mqclient

  1. #1
    Join Date
    Aug 2005
    Location
    Saarbrücken/Karlsruhe/Germany
    Posts
    2

    Default 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. #2
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    45

    Default

    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 at 07:54 AM.

  3. #3
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    45

    Default

    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

Similar Threads

  1. Replies: 1
    Last Post: Jan 27th, 2005, 06:00 PM
  2. Problem using Native SQL
    By Aslam in forum Data
    Replies: 4
    Last Post: Jan 20th, 2005, 04:56 PM
  3. Replies: 3
    Last Post: Sep 28th, 2004, 10:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •