RabbitMQ(二) 手动确认消费
2020-08-19 本文已影响0人
尼尔君
手动确认消费
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 -> {
});
}