问题
JMS using in spring, how to config and what type of dependency to use
回答1:
There are some caveats with Spring JMS.
- 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.
- 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.
回答2:
You could check out Spring in Action. It has a chapter about messaging using JMS from Spring which I found helpful.
来源:https://stackoverflow.com/questions/793042/step-by-step-sample-jms-in-spring-framework