Exercise extreme caution when using the Spring JMSTemplate with JBoss Messaging.
The Spring JMSTemplate code employs several anti-patterns, like creating a new connection, session, producer just to send a message, then closing them again.
Also when receiving a message it can create a consumer each time, receive the message then close it.
This not only results in very poor performance, but can also make you run out of operating system resources such as threads and file handles, since some of the connection resources are released asynchronously.
Moreover with non durable consumers you can end up losing messages, since any messages received between the closing of the last and opening of the next consumer will be lost.
There is one place where it may be acceptable to use the Spring JMSTemplate and that's inside the application server using the JCA managed connection factory (normally at /JmsXA) and that only works when you're sending messages.
The JCA managed connection factory caches connections so they won't actually be created each time. However using the JCA managed connection factory won't resolve the issue with consumers since they are not cached.
In summary, the Spring JMSTemplate is not safe to use with JBoss Messaging apart from the very specific use case of using it inside the application server with the JCA managed connection factory (/JmsXA) and only in that case to send mesages (don't use it to consume messages).
Using it from a JMS client application outside the application server is never safe with JBoss Messaging, and using it with a standard connection factory (e.g. /ConnectionFactory or /ClusteredConnectionFactory) is never safe, also using it to receive messages with JBoss Messaging is never safe.
Please note that this problem is not specific to JBoss Messaging. Check out this ActiveMQ page for example http://activemq.apache.org/jmstemplate-gotchas.html, they suffer from similar problems. Also exactly the same reasoning applies to JBoss MQ.
Please note that JBoss / Red Hat will not support people using the Spring JMSTemplate with JBoss Messaging apart from the one acceptable use case for the reasons outlined above.