手动确认消费
private static void consumeMsg(ConnectionFactory connectionFactory) throws IOException, TimeoutException {
Connection connection = connectionFactory.newConnection();
Channel channel = connection.createChannel();
channel.basicQos(1);
channel.queueDeclare("nihao", false, false, false, null);
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
String message = new String(delivery.getBody(), "UTF-8");
System.out.println(" [x] Received '" + message + "'");
channel.basicAck(delivery.getEnvelope().getDeliveryTag(),false);
};
channel.basicConsume("nihao", false, deliverCallback, consumerTag -> {
});
}
网友评论