View Full Version : What is the proper usage of ConcurrentConsumers property?
keenan
08-06-2008, 04:59 PM
Given this configuration:
<object id="messageListener" type="MySample.MessageConsumerTest, MySample" />
<object id="nmsContainer" type="Spring.Messaging.Nms.Listener.SimpleMessageListene rContainer, Spring.Messaging.Nms">
<property name="ConnectionFactory" ref="mqConnFactory"/>
<property name="DestinationName" value="test.queue"/>
<property name="ConcurrentConsumers" value="5"/>
<property name="MessageListener" ref="messageListener"/>
</object>
What is the expected behavior of the ConcurrentConsumers property?
It does not appear that multiple threads are created to watch the queue.
Mark Pollack
08-06-2008, 06:51 PM
Hi,
Multiple threads will be created but they are created/owned by NMS itself when creating a MessageConsumer. The relevant bit of code is in the method InitializeConsumers where it does the following
for (int i = 0; i < this.concurrentConsumers; i++)
{
ISession session = CreateSession(SharedConnection);
IMessageConsumer consumer = CreateListenerConsumer(session);
this.sessions.Add(session);
this.consumers.Add(consumer);
}
One thing to be aware of is that with ActiveMQ/NMS there is a property that determines how many messages to 'pre-fetch'. See this link (http://activemq.apache.org/what-is-the-prefetch-limit-for.html). The default value is 1000 so that means the first message consumer will get 1000 messages even if there are other consumers available. The default seems to be this large assuming you are going to consume at high rates on a topic by default.
If this is in fact what is happening, I don't see the property ActiveMQPrefetchPolicy on the NMS Connection or ConnectionFactory, though the above link says it can also be specified on the queue level via a name like this "TEST.QUEUE?consumer.prefetchSize=10"
Which version of Spring.NET are you using BTW, I've been mucking with the code a fair bit, though the creation of multiple consumers has been in there for a long time i believe.
If you could try out the queue configuration and let me know, I'd appreciate it. Sample code to reproduce it would also be welcome!
Cheers,
Mark
keenan
08-08-2008, 04:20 AM
One thing to be aware of is that with ActiveMQ/NMS there is a property that determines how many messages to 'pre-fetch'. See this link (http://activemq.apache.org/what-is-the-prefetch-limit-for.html).
Thank you! I'm new to ActiveMQ and I had no idea about the prefetch property. The reason I was confused about the ConcurrentConsumers property was that my sample application seemed to be dominated by a single consumer. Now I know why :)
Which version of Spring.NET are you using BTW, I've been mucking with the code a fair bit
I was using the 2008-08-04 nightly build. I had pulled down the source from subversion and I admit I got confused because I was looking at the source code from 08-05 to figure out which classes I needed but they weren't in the auto-complete for Visual Studio. Finally I looked at the SVN history and saw that there were namespace and class name changes around that time.
If you could try out the queue configuration and let me know, I'd appreciate it. Sample code to reproduce it would also be welcome!
I put together a small application with a Producer.cs which simply writes messages to a queue on startup. The Consumer.cs implements IMessageListener and writes out the message text to console. I don't know if you will find it of any use, but I'll attach it.
I am running against an "out-of-the-box" ActiveMQ 5.1.0
Note that this project runs against the 2008-08-04 build, but I think only Config.xml needs to change in order to work against the newer builds.
Thanks for your speedy responses on this forum and hard work on Spring.NET in general. It is very much appreciated!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.