QueueingConsumer consumer = new QueueingConsumer(channel);
System.out.println(consumer.getConsumerTag());
channel.basicConsume("queue1", consumer);
channel.basicConsume("queue3", consumer);
是否可以停止使用队列中的消息" queue3"单独动态?
答案 0 :(得分:22)
是的,你可以使用channel.basicCancel(consumerTag);
的修改
例如:
String tag3 = channel.basicConsume("queue3", consumer);
channel.basicCancel(tag3)
在这里,您可以找到在5秒后取消订阅消费者的代码:
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
我希望它有用。