Results 1 to 2 of 2

Thread: How to prevent createConnection() from being called by the jmsTemplate.send() method

  1. #1
    Join Date
    May 2012
    Location
    NY
    Posts
    23

    Default How to prevent createConnection() from being called by the jmsTemplate.send() method

    I am using a SingleConnectionFactory. My application listens on one topic A and publishes to another topic B. Since I want this to happen in one session I use a single connectionFactory.
    this is what my onMessage looks like in my MessageListener. (jmsTemplate is injected into my message listener via the constructor)

    Code:
    public void onMessage(Message message) {
    		jmsTemplate.send(destination, new MessageCreator() {
    			public Message createMessage(Session session) throws JMSException {
    				Message message = session.createMessage();
    				//TODO: do something
    				return message;
    			}});
    			sender.send(fdrMessage);	
    	}
    However the jmsTemplate.send call makes the following calls internally:

    Code:
    org.springframework.jms.core.JmsTemplate.send()
    org.springframework.jms.core.JmsTemplate.execute()
    org.springframework.jms.support.JmsAccessor.createConnection()
    org.springframework.jms.connection.SingleConnectionFactory.createConnection()
    Which results in an exception:javax.jms.InvalidClientIDException: clientId already exists (because it is trying to create a connection using the same connectionFactory.)

    How do I force jmsTemplate to use the connection within which the onMessage() call was invoked? I don't want it to create a new connection.
    Last edited by sur4@njit.edu; May 9th, 2012 at 05:26 PM.

  2. #2
    Join Date
    May 2012
    Location
    NY
    Posts
    23

    Default

    got the problem. The createConnection was being called from different threads. The first time it is called when my dmlc calles it on dmlc.start() and the second time it is called on the new thread in onMessage()

Tags for this Thread

Posting Permissions

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