Hi all,
I am using the receive() method on the JmsTemplate. The program runs at a set interval and counts the number of messages currently on the queue and pulls them off one at a time. I am using CLIENT_ACKNOWLEDGE mode so I have to wrap the JmsTemplate code in a transaction to prevent the template from closing the session before I can acknowledge the message. So... when the program completes, a JMS Connection is left hanging open.
How to I force the JmsTemplate to close the connection? This is causing the java.exe to keep running and not complete. I am using Spring 3.1.0
Thanks!
Nathan
I am using the receive() method on the JmsTemplate. The program runs at a set interval and counts the number of messages currently on the queue and pulls them off one at a time. I am using CLIENT_ACKNOWLEDGE mode so I have to wrap the JmsTemplate code in a transaction to prevent the template from closing the session before I can acknowledge the message. So... when the program completes, a JMS Connection is left hanging open.
How to I force the JmsTemplate to close the connection? This is causing the java.exe to keep running and not complete. I am using Spring 3.1.0
Code:
//This transaction is needed to prevent the JmsTempate from closing the session after the receive method is called.
TransactionStatus status = txManager.getTransaction(new DefaultTransactionDefinition());
//Get the number of messages on the queue and process them.
int messageCount = JmsUtil.countMessagesOnQueue(jmsTemplate, subscribeQueue);
LOG.info("Found " + messageCount + " messages(s) on the queue.");
for (int i = 0; i < messageCount; i++) {
Message message = jmsTemplate.receive(subscribeQueue);
//..more code here
}
message.acknowledge();
txManager.commit(status);
HTML Code:
<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
p:connectionFactory-ref="cacheJmsConnectionFactory"
p:sessionAcknowledgeMode="2" <!-- CLIENT_ACKNOWLEDGE -->
p:defaultDestination-ref="publishQueue"
p:pubSubDomain="false"
p:receiveTimeout="-1"/> <!-- Don't wait if a message isn't there -->
</beans>
Nathan