background preloader

Async

Facebook Twitter

Spring

Www.springsource.com/files/uploads/all/pdf_files/news_event/Introduction_to_Apache_ActiveMQ_Webinar_Slides.pdf. Using Spring to Send JMS Messages. Recently I stumbled upon a number of places in the some docs and mailing lists where claims are made that the Spring JmsTemplate is full of anti-patterns, is horribly inefficient and shouldn't be used.

Well I'm here to debunk these erroneous claims by pointing out a class in the Spring Framework that was overlooked entirely. The Spring JmsTemplate is a convenience class for sending and receiving JMS messages in a synchronous manner. The JmsTemplate was originally designed to be used with a J2EE container where the container provides the necessary pooling of the JMS resources (i.e., connections, consumers and producers). Such requirements came from the EJB spec. The CachingConnectionFactory is meant to wrap a JMS provider's connection to provide caching of sessions, connections and producers as well as automatic connection recovery. Below is a snippet from a Spring app context that demonstrates the configuration for the CachingConnectionFactory. February 2010. Have you ever had a need to create your own JMS consumer? Or will you have this need in the future? If you answered yes to either one of these questions, this post will simplify your life. In the previous post, I discussed Using the Spring JmsTemplate to Send JMS Messages.

As a follow-on, in this post I will demonstrate how to receive messages using Spring JMS. Although the previously mentioned JmsTemplate can receive messages synchronously, here I will focus on asynchronous message reception using the Spring message listener container architecture, specifically the DefaultMessageListenerContainer. The DefaultMessageListenerContainer (DMLC) is another wonderful convenience class that is part of the Spring Framework's JMS package. As you can see in the Javadoc, the DMLC is not a single class, but a well-abstracted hierarchy for the purpose of receiving messages. Compared to MDBs, use of the Spring DMLC is actually surprisingly simple. Below is the message listener implementation: Tuning JMS Message Consumption In Spring.

In a previous blog post titled Using Spring to Receive JMS Messages, I introduced the use of the Spring default message listener container for asynchronous consumption of JMS messages. One very common discovery that folks make when first using JMS is that producers can send messages much faster than consumers can receive and process them. When using JMS queues, I always recommend the use of more consumers than you have producers. (When using JMS topics, you should only use a single consumer to guard against receiving the same message multiple times.) This is a normal situation with message-oriented middleware (MOM) and it is easy to handle if you are using the Spring message listener container.

Notice the concurrency="10-50" property above. (NOTE: The idleConsumerLimit property is used to specify the the maximum number of consumers that are allowed to be idle at a given time. It is important to be aware of a couple of things related to this dynamic scaling: Java - Spring 3.0 lazy-init not honoured for DefaultMessageListenerContainer. DefaultMessageListenerContainer and Tibco EMS very low throughput [Archive] - Spring Community Forums.

Core JMS

Camel.