美文网首页
RabbitMQ(二) 手动确认消费

RabbitMQ(二) 手动确认消费

作者: 尼尔君 | 来源:发表于2020-08-19 13:02 被阅读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 -> {
    
                });
    
        }
    
    

    相关文章

      网友评论

          本文标题:RabbitMQ(二) 手动确认消费

          本文链接:https://www.haomeiwen.com/subject/apvrjktx.html