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.