Hi Eugeny,

As James stated earlier - you need to set the prefetch - but the value should be 0 - this will make ActiveMQ 'pull' rather than 'push'

cheers,

Rob

Rob Davies
http://fusesource.com
http://rajdavies.blogspot.com/


On 29 Oct 2008, at 15:07, Eugeny N Dzhurinsky wrote:

On Tue, Oct 28, 2008 at 05:44:26PM +0000, James Strachan wrote:
2008/10/28 Eugeny N Dzhurinsky <[EMAIL PROTECTED]>:
Hello!

I am facing some strange issue with acknowledge mode in ActiveMQ. After reading the specs, I realized the broker will never deliver a message to the consumer unless the consumer acknowledges the previous message. So I thought it is enough to not send the acknowledgement message to the server in the onMessage method of the consumer and sent it later from another thread, which does it's job. This means I spawn a thread when onMessage is called and forget
about it in this method.
You should only be using a JMS session from one thread at once - so
you should call message.acknowlege() from the consumer thread.

  final MessageConsumer consumer = serverSession
          .createConsumer(serverQueue);
  consumer.setMessageListener(new MessageListener() {

      public void onMessage(final Message message) {
          System.out.println("Got message");
          try {
              System.out.println(message.getStringProperty(DATA));
              // message.acknowledge();
              successCount.incrementAndGet();
          } catch (final Exception e) {
              e.printStackTrace();
          }
      }

  });

Calling or not calling acknowledge doesn't make any difference - as soon as
onMessage returns, the next message is delivered to the consumer.

If you don't want the message broker to send another message to the
consumer until it is acknowledged, set prefetch to 1
http://activemq.apache.org/what-is-the-prefetch-limit-for.html

private static final String CONNECTION_URL = "vm://localhost? broker.persistent=false&jms.prefetchPolicy.all=1";

I am doing in this way, as can be found in the source I originally posted.

So is there a bug in ActiveMQ regarding the acknowledge mode or I still
missing something?

--
Eugene N Dzhurinsky

Reply via email to