activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Santillan <>
Subject Re: Question on consumers
Date Tue, 03 May 2011 18:05:36 GMT
Thanks a lot Martin. This is very helpful.

With this, I'd like to verify if my understanding is correct through the 
following code snippet:

ActiveMQConnectionFactory connectionFactory = new 

Connection connection = connectionFactory.createConnection();

Destination destination = connection.createSession(isTransacted, 

MessageProducer producer = connection.createSession(isTransacted, 

MessageConsumer consumer1 = connection.createSession(isTransacted, 
consumer1.setMessageListener(new ConcreteMessageListenerImpl());
MessageConsumer consumer2 = connection.createSession(isTransacted, 
consumer2.setMessageListener(new ConcreteMessageListenerImpl());
MessageConsumer consumer3 = connection.createSession(isTransacted, 
consumer3.setMessageListener(new ConcreteMessageListenerImpl());
MessageConsumer consumer4 = connection.createSession(isTransacted, 
consumer4.setMessageListener(new ConcreteMessageListenerImpl());
MessageConsumer consumer5 = connection.createSession(isTransacted, 
consumer5.setMessageListener(new ConcreteMessageListenerImpl());


On Tuesday, 03 May, 2011 08:13 PM, Martin C. wrote:
> Hi,
> the JMS threading model is based around the Session. Each Session is
> to be used by one thread. If you are using asynchronous mode (you
> register a MessageListener with the Session), every Session uses one
> thread or is to be used by one thread
> ( If
> you attach 5 consumers to a single session, only one of them will be
> called. You need 5 Sessions with each 1 consumer in order to feed 5
> consumers in parallel in asynchronous mode.
> This is not strictly speaking the truth, because in theory you may use
> a Session with more than one thread, but you need to ensure proper
> synchronization. If you are using asynchronous messaging, the
> following from
> holds:
> <quote>Each session must insure that it passes messages serially to
> the listener. This means that a listener assigned to one or more
> consumers of the same session can assume that the onMessage method is
> not called with the next message until the session has completed the
> last call.</quote>
> So if you want to go parallel, you need to create more Sessions and
> MessageConsumers.
> Best regards,
> Martin
> On Mon, May 2, 2011 at 11:50 AM, Don Santillan<>  wrote:
>> Hello,
>> I have a basic question about message consumers that I really need to
>> confirm that my understanding is correct.
>> Do message consumers run in different threads?
>> Suppose I have 5 consumers assigned to a queue. Are these consumers
>> independent with each other and are running in different threads?
>> Thanks!

View raw message