activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: Consumer not consume message
Date Tue, 23 Apr 2013 10:12:20 GMT
On 04/23/2013 01:18 AM, Balachandar R.A. wrote:
> Hello,
>
> I have an issue. I push 100 messages to the queue with one consumer
> initially. The consumer takes the message and starts working. After few
> seconds, I start another consumer. The second consumer does not take any
> messages from the queue eventhough there are messages pending in the queue.
> Ideally, I would expect the second consumer takes the message and process
> so that all the messages are processed quickly. Any fix to this?
>
> In my producer side, I use
>
> // Create a connection factory
>               ConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory(server)
>
>              // Create a connection and start
>              Connection connection = connectionFactory.createConnection()
>
>              connection.start()
>
>              // Create a Session
>              Session session =
> connection.createSession(false,Session.AUTO_ACKNOWLEDGE)
>
>              // Create the destination
>              // PHOTOGRAMMETRY_MQ is the queue name
>              Destination destination =
> session.createQueue("PHOTOGRAMMETRY_MQ")
>
>              // Create a MessageProducer from the Session to the Topic or
> Queue
>              MessageProducer producer = session.createProducer(destination)
>              producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT)
>
>              // Send the message
>              TextMessage message = session.createTextMessage(args)
>              producer.send(message)
>
> In my consumer side, I use the code below
>
> // Creates a connection factory
>              connectionFactory = new ActiveMQConnectionFactory(server)
>              consumerfactory = new ConsumerFactory()
>
>              // Create and start a Connection
>              connection = connectionFactory.createConnection()
>              connection.start()
>
>              // Create a Session
>              Session session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE)
>
>              // Create a queue
>              Destination destination =
> session.createQueue("PHOTOGRAMMETRY_MQ")
>
>              // Create a MessageConsumer
>              MessageConsumer m_cons = session.createConsumer(destination)
>              boolean flag = true
>              while (flag){
>                  // Receive message
>                  Message message = m_cons.receiveNoWait()
>
>
>
> With thanks and regards
> Balachandar
>

Read up on prefetch and consumers
http://activemq.apache.org/what-is-the-prefetch-limit-for.html

Most likely all your messages are in the first consumers prefetch buffer.

-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/


Mime
View raw message