activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcm231 <>
Subject Re: Problem with message groups
Date Tue, 19 Jun 2007 09:57:42 GMT

James.Strachan wrote:
> On 6/18/07, jcm231 <> 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.
> to mimick round-robin, try setting the prefetch to 1 on both
> consumers; or try using thousands of messages
> -- 
> James
> -------

I have sent 34000 messages but they all get consumed by the same consumer. 

I tried to specify the prefetchSize as indicated in:

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">    

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)
        queue = (Queue) jndiContext.lookup(queueName);
      } catch (NamingException e) {
        System.out.println("JNDI API lookup failed: " + e.getMessage());
      try {
        queueConnection =
queueConnectionFactory.createQueueConnection("User", "Password");
        queueSession = queueConnection.createQueueSession(false,
        queueReceiver = queueSession.createReceiver(queue);
        // Creating two consumers
        Consumer cons1 = new Consumer("cons1");
	Consumer cons2 = new Consumer("cons2");
        // Setting cons1 as listener
        // Setting cons2 as listener
        new Thread(cons1).start();
        new Thread(cons2).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:
Sent from the ActiveMQ - User mailing list archive at

View raw message