You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by techbuddy <sa...@yahoo-inc.com> on 2012/01/02 08:28:01 UTC
Messages getting dispatched in a single thread
Hi,
I wrote up a sample message consumer app to test AMQ message processing
functionality.
The app creates a single broker connection and 3 consumer sessions, each
further creating a separate MessageConsumer object. The message consumers
are registered to a queue on the Broker.
Before launching the consumer app, I get 5 messages posted to the queue
through another app (call it the producer app).
Now, on launching the consumer app, I expect the consumers to be started up
in three *different *threads, as each of them belong to a different session
( all the sessions ,however, share the same broker connection). So the 5
pending messages should get dispatched to three threads and processing
should happen concurrently.
However I find that the messages are getting processed sequentially in a
single thread by a single consumer. Could someone please explain the
sequential processing, as opposed to the expected concurrent processing?
Here's the consumer app code
http://activemq.2283324.n4.nabble.com/file/n4252635/TestAMQ.java
TestAMQ.java
Following is the output. Note that all the messages got processed by
consumer cons_1, though all the three got created (each in a different
session)
Created consumer 1
Created consumer 2
ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........4'
Created consumer 3
main : Created the consumers
ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........4'
ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........3'
ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........3'
ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........2'
ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........2'
ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........1'
ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........1'
ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........5'
ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........5'
--
View this message in context: http://activemq.2283324.n4.nabble.com/Messages-getting-dispatched-in-a-single-thread-tp4252635p4252635.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
RE: Messages getting dispatched in a single thread
Posted by techbuddy <sa...@yahoo-inc.com>.
Found the culprit. The issue was in the TestCode
The prefetch limit was not getting set correctly. Setting it through the
props file was not happening.
I tried with explicit setting of this property through the following, and
the concurrency worked as expected
*((ActiveMQConnectionFactory)connectionFactory).getPrefetchPolicy().setQueuePrefetch(1);*
I did another negative test by setting the prefetch limit to 10 ( the number
of consumer sessions is 3), and found the processing happening sequentially.
*Take away* : If the prefetch limit is more than 1, AMQ would tend to
dispatch the messages to a single consumer session, even though there are
multiple active consumer sessions (each with a different
MessageConsumer/Listener on the same queue) available.
--
View this message in context: http://activemq.2283324.n4.nabble.com/Messages-getting-dispatched-in-a-single-thread-tp4252635p4268445.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
RE: Messages getting dispatched in a single thread
Posted by Allen Reese <ar...@yahoo-inc.com>.
I think it's covered in the fuse docs here:
http://fusesource.com/wiki/display/ProdInfo/Understanding+the+Threads+Allocated+in+ActiveMQ
1 thread per session.
--Allen Reese
Yahoo! Inc.
> -----Original Message-----
> From: techbuddy [mailto:santoshb@yahoo-inc.com]
> Sent: Sunday, January 01, 2012 11:28 PM
> To: users@activemq.apache.org
> Subject: Messages getting dispatched in a single thread
>
> Hi,
>
> I wrote up a sample message consumer app to test AMQ message processing
> functionality.
>
> The app creates a single broker connection and 3 consumer sessions,
> each further creating a separate MessageConsumer object. The message
> consumers are registered to a queue on the Broker.
>
> Before launching the consumer app, I get 5 messages posted to the queue
> through another app (call it the producer app).
>
> Now, on launching the consumer app, I expect the consumers to be
> started up in three *different *threads, as each of them belong to a
> different session ( all the sessions ,however, share the same broker
> connection). So the 5 pending messages should get dispatched to three
> threads and processing should happen concurrently.
>
> However I find that the messages are getting processed sequentially in
> a single thread by a single consumer. Could someone please explain the
> sequential processing, as opposed to the expected concurrent
> processing?
>
>
> Here's the consumer app code
>
> http://activemq.2283324.n4.nabble.com/file/n4252635/TestAMQ.java
> TestAMQ.java
>
> Following is the output. Note that all the messages got processed by
> consumer cons_1, though all the three got created (each in a different
> session)
>
>
>
> Created consumer 1
> Created consumer 2
> ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........4'
> Created consumer 3
> main : Created the consumers
> ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........4'
>
> ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........3'
> ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........3'
>
> ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........2'
> ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........2'
>
> ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........1'
> ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........1'
>
> ActiveMQ Session Task-1 : : cons_1 Received message 'Msg ..........5'
> ActiveMQ Session Task-1 : cons_1 Processed message 'Msg ..........5'
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Messages-getting-dispatched-in-a-
> single-thread-tp4252635p4252635.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.