企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
声明惰性队列在消费者设置参数`params.put("x-queue-mode", "lazy")`即可。 ```java public class LazyConsumer { private static final String QUEUE_NAME = "queue.hello.lazy"; public static void main(String[] args) throws Exception { Channel channel = RabbitMQUtils.getChannel(); Map<String, Object> params = new HashMap(16); //声明为惰性队列 params.put("x-queue-mode", "lazy"); channel.queueDeclare(QUEUE_NAME, true, false, false, params); System.out.println(LazyConsumer.class.getSimpleName() + "[等待消费..]"); DeliverCallback deliverCallback = (consumerTag, delivery) -> { String message = new String(delivery.getBody()); System.out.println(LazyConsumer.class.getSimpleName() + "[收到消息]: " + message); }; channel.basicConsume(QUEUE_NAME, true, deliverCallback, (consumerTag) -> { }); } } ``` **** 案例代码:https://gitee.com/flymini/codes01/tree/master/rabbitmq_/com-learn-rabbitmq04