Announcement Announcement Module
Collapse
No announcement yet.
How to prevent createConnection() from being called by the jmsTemplate.send() method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 [email protected]; May 9th, 2012, 05:26 PM.

  • #2
    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()

    Comment

    Working...
    X