tags:

views:

2682

answers:

3

JMS using in spring, how to config and what type of dependency to use

+3  A: 

This helped me a while back:

Asynchronous Messaging Made Easy With Spring JMS

sal
+3  A: 

There are some caveats with Spring JMS.

  1. You absolutely must not use Spring JMS directly on a JMS connection factory. This is because Spring - particularly JmsTemplate - opens a connection, uses it for one message, then closes it. This is the correct pattern to use when the connection factory is, in fact, a connection pool. But if it is really just a connection factory, you're going to slaughter the server under load. This is normally only an issue when you're running a standalone application rather than inside of a J2EE container, which typically has resource adapters or other things that do pooling for you. Spring does supply a SingleConnectionFactory bean that will reuse a connection, but this is not the best solution when you're using a clustered server and want to load balance your connections and work.
  2. The Spring APIs are all designed around processing single messages at a time. In some cases, where you may be able to deal with a batch of messages, it may be preferable to use Spring to provide you with the connection factories and such, but roll your own code to actually do the message I/O. That way, you can, for example, set up a transacted session, process 100 messages, then commit the acknowledgment as a batch. That should reduce the workload on the server, assuming you can do so safely.
nsayer
Are "Spring APIs are all designed around processing single messages at a time" I don't think so. If you are consuming messages just define a DefaultMessageListenerContainer or similar, then all you need to do is define an onMessage method to consume the messages. You can increase and decrease the consumers at runtime or configuration time.
Shawn
+1  A: 

You could check out Spring in Action. It has a chapter about messaging using JMS from Spring which I found helpful.

Mattias Holmqvist