James.Strachan wrote:
>
> On 6/18/07, jcm231 <[EMAIL PROTECTED]> wrote:
>>
>> Hi!
>>
>> I am have a standalone ActiveMQ server and I am sending messages using a
>> producer. The messages include the JMSXGroupID header with two different
>> values: "one" and "two". I launch two Consumer objects, both being
>> threads
>> and implementing the interface MesageListener. The result is that only
>> one
>> of the two consumers receives all the messages. Sometimes is the first
>> consumer and sometimes is the second who receives them all.
>>
>> What am I doing wrong? It is the first time I use ActiveMQ and I would
>> thank
>> any help anybody could give me.
>
> We don't yet guarrentee an exact round-robin dispatch policy on a per
> message group basis; consumers tend to eagerly grab as many messages
> as will fit into their pre-fetch buffer.
> http://activemq.apache.org/what-is-the-prefetch-limit-for.html
>
> to mimick round-robin, try setting the prefetch to 1 on both
> consumers; or try using thousands of messages
>
>
>
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
>
I have sent 34000 messages but they all get consumed by the same consumer.
I tried to specify the prefetchSize as indicated in:
http://activemq.apache.org/what-is-the-prefetch-limit-for.html
but I am not creating the ActiveMQQueue on the consumer's code but on the
xml file. So I put this on my activemq.xml file:
<!-- Destination -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg>
<value>example.MyQueue?consumer.prefetchSize=1;consumer.exclusive=false</value>
</constructor-arg>
</bean>
but it seems not be effective.
On the class that launches the consumers, I am getting the queueReceiver via
JNDI, so maybe the way I indicate the prefetch size is wrong, I do not know:
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("jms/MYQUEUE");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.getMessage());
System.exit(1);
}
try {
queueConnection =
queueConnectionFactory.createQueueConnection("User", "Password");
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
// Creating two consumers
Consumer cons1 = new Consumer("cons1");
Consumer cons2 = new Consumer("cons2");
// Setting cons1 as listener
queueReceiver.setMessageListener(cons1);
// Setting cons2 as listener
queueReceiver.setMessageListener(cons2);
new Thread(cons1).start();
new Thread(cons2).start();
queueConnection.start();
} catch (JMSException e) {
System.out.println("Exception ocurred: " + e.getMessage());
}
cons1 and cons2 implement Runnable and MessageListener but only one of them
is receiving the messages.
The idea is to use the message groups feature of ActiveMQ for our project,
because we need to assure that all the messages with the same id (in the
JMSXGroupId header) are consumed by the same consumer. Could be using
selectors a better aproach? How can I get message groups working?
--
View this message in context:
http://www.nabble.com/Problem-with-message-groups-tf3941180s2354.html#a11191679
Sent from the ActiveMQ - User mailing list archive at Nabble.com.