赞
踩
RabbitMQ创建队列之后,如果需要改为持久化的队列,如果一开始没有指定或者指定durable属性为false,默认不持久化队列,当使用如下代码
package com.atguigu.rabbitmq.three;
import com.atguigu.rabbitmq.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import java.util.Scanner;
/**
* @author kiki
* @date 2022/6/30
* @description 消息在手动应答时是不丢失、放回队列中重新进行消费
*/
public class task2 {
public static final String TASK_QUEUE_NAME = "ack_queue";
public static void main(String[] args) throws Exception {
Channel channel = RabbitMQUtil.getChannel();
boolean durable = true;
//声明队列
channel.queueDeclare(TASK_QUEUE_NAME,durable,false,false,null);
//从控制台输入信息
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()){
String message = scanner.next();
channel.basicPublish("",TASK_QUEUE_NAME,null,message.getBytes("UTF-8"));
System.out.println("生产者发出消息:"+message);
}
}
}
指定队列持久化,此时会报
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'ack_queue' in vhost '/': received 'true' but current is 'false', class-id=50, method-id=10)
此时需要去客户端RabbitMQ
去删除队列,然后重新创建才可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。