[rabbitmq-discuss] rabbitmq java client keeps pulling data?
DeepNightTwo
DeepNightTwo at gmail.com
Fri Sep 19 09:08:48 BST 2014
Is it designed so for some purpose? My understanding is, if a fixed-size
queue is used to create a consumer, it is expected the consumer should stop
pulling data if the queue is full.
I extends from QueueingConsumer and it works for me.
class BlockingConsumer extends QueueingConsumer {
private BlockingQueue<Delivery> q;
public BlockingConsumer(Channel ch) {
super(ch);
}
public BlockingConsumer(Channel ch, LinkedBlockingDeque<Delivery> q) {
super(ch, q);
this.q = q;
}
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte[] body) throws IOException {
if (q == null) {
super.handleDelivery(consumerTag, envelope, properties, body);
} else {
try {
this.q.put(new Delivery(envelope, properties, body));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
q.put will block until the queue has a slot available. But I'm not sure if
this will bring network issue. For example, if the queue keeps full, will
the connection be timeout/reset?
And this impl is ugly.
Because the _queue is private, I have to store a reference in subclass. And
because the _checkShutdown method is private, I didn't invoke it in the sub
class.
--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/rabbitmq-java-client-keeps-pulling-data-tp37080p37082.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss
mailing list