QueueingConsumer consumer = new QueueingConsumer(channel);
System.out.println(consumer.getConsumerTag());
channel.basicConsume("queue1", consumer);
channel.basicConsume("queue3", consumer);
Is it possible to stop consuming the messages from the queue "queue3" alone dynamically?
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user... @googlegroups.com.
You can enable de-duplication on a queue via setting its x-message-deduplication argument to true . Then, your publishers will need to provide the x-deduplication-header message header with a value meaningful for de-duplication. The value could be a unique message ID or the MD5 / SHA1 hash of the body for example.
You will have to cancel the consumer in your on_request method. You can also use this method to consume messages which allows an inactivity_timeout to be set, where you could then cancel your consumer.
RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers. The hash exchange distributes routing keys among queues, instead of messages among queues. This means all messages with the same routing key will go the same queue.
Yes you can, using channel.basicCancel(consumerTag);
EDIT
For example:
String tag3 = channel.basicConsume("queue3", consumer);
channel.basicCancel(tag3)
Here you can find a code that unsubscribe a consumer after 5 seconds:
String tag1 = channel.basicConsume(myQueue, autoAck, consumer);
String tag2 = channel.basicConsume(myQueue2, autoAck, consumer);
executorService.execute(new Runnable() {
@Override
public void run() {
while (true) {
Delivery delivery;
try {
delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println("Received: " + message);
} catch (Exception ex) {
Logger.getLogger(TestMng.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
System.out.println("Consumers Ready");
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(TestMng.class.getName()).log(Level.SEVERE, null, ex);
}
channel.basicCancel(tag2); /// here you remove only the Myqueue2
I hope it can be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With