basicQos Confusion in Java Client 3.5.4 (Server 3.5.3)

43 views
Skip to first unread message

Dave Seltzer

unread,
Aug 31, 2015, 10:11:59 AM8/31/15
to rabbitmq-users
Hello,

I'm having trouble restricting the prefetch count in Java Client 3.5.4 connecting to server 3.5.3.

Here's how I'm setting up my connection:

ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(BrokerUsername);
factory.setPassword(BrokerPassword);
factory.setVirtualHost(BrokerVirtualHost);
factory.setHost(BrokerHostname);
Connection conn = factory.newConnection();
Channel channel = conn.createChannel();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(InboundQueueName, autoAck, consumer);
channel.basicQos(50, true);
while(true) {
    QueueingConsumer.Delivery delivery = consumer.nextDelivery(1000);
    Envelope envelope = delivery.getEnvelope();
    if(delivery != null) {
        //do something
        consumer.getChannel().basicAck(envelope.getDeliveryTag(), false);
    }
}

The problem I'm having is that the server seems to be sending way more that 50 messages to the client. I think I must be mis-using basicQos, or maybe I have a fundamental misunderstanding of how it works.

Any help would be hugely appreciated! (Details follow)

Thanks!

-Dave


In this example I have one consumer with a single thread. For some reason the Queue shows the Prefetch count = 0 even though there are 126 Unacked messages. The Queue looks like this:










































When I drill down to the channel level I see that there is a global prefetch count of 50 set on the consumer but that the consumer still has 200 unacked messages:


Michael Klishin

unread,
Aug 31, 2015, 10:40:23 AM8/31/15
to rabbitm...@googlegroups.com, Dave Seltzer
On 31 August 2015 at 17:12:02, Dave Seltzer (dsel...@tveyes.com) wrote:
> QueueingConsumer consumer = new QueueingConsumer(channel);
> channel.basicConsume(InboundQueueName, autoAck, consumer);
> channel.basicQos(50, true);

Invoke basicQos _before_ you add a consumer.

Unrelated: don't use QueueingConsumer if you can help it (as to why, it  has been discussed
many times before on the list).
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Dave Seltzer

unread,
Aug 31, 2015, 11:05:49 AM8/31/15
to rabbitmq-users
Awesome, that did the trick! 

Thanks so much!

-Dave
Reply all
Reply to author
Forward
0 new messages