ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的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