我正在尝试使用ConfirmListener但执行永远不会到达其方法.我是这样做的:
channel.addConfirmListener(new ConfirmListener() {
public void handleNack(long deliveryTag, boolean multiple) throws IOException {
System.out.println("Not ack received");
}
public void handleAck(long deliveryTag, boolean multiple) throws IOException {
System.out.println("Ack received");
}
});
channel.exchangeDeclare(directExchangeName, directExchangeType, DURABLE, AUTO_DELETE, arguments);
channel.queueBind(directQueueName, directExchangeName, routingKey);
// AUTO_ACK = false
channel.basicConsume(directQueueName, AUTO_ACK, routingKey, directConsumer);
Run Code Online (Sandbox Code Playgroud)
然后我用这个发表:
channel.basicPublish(directExchangeName, routingKey, MANDATORY, properties, message.getBytes());
Run Code Online (Sandbox Code Playgroud)
后来我用这个消费了:
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
// Send ack
channel.basicAck(envelope.getDeliveryTag(), false);
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
谢谢,欢呼.