我在配置文件中写入了
rabbitmq: host: 127.0.0.1 port: 5672 username: guest passport: guest virtualhost: / switchFlag: true pool_size: 10
然后希望实现一个监听器,所以加上了注解形式@RabbitListener(queues = CommonConstants.QUERE_NAME_NOTIFY)
,由于我工作环境原因,在不同电脑上coding(笔记本没有安装rabbitMQ),为了能否方便使用配置文件中的switchFlag进行切换,所以使用了@ConditionalOnProperty(value = "rabbitmq.switchFlag")
,但是我今天心血来潮,想把direct的exchange切换成topic,由于之前的做法是`public void run(ApplicationArguments args) throws Exception {
String host = rabbitmqProperties.getHost();
Integer port = rabbitmqProperties.getPort();
String userName = rabbitmqProperties.getUsername();
String password = rabbitmqProperties.getPassport();
String virtualhost = rabbitmqProperties.getVirtualhost();
Integer poolSize = rabbitmqProperties.getPoolSize();
RabbitmqConnectionPool.initRabbitmqConnectionPool(host, port, userName, password, virtualhost, poolSize);
RabbitmqConnection connection = RabbitmqConnectionPool.getConnection();
Channel channel = connection.getConnection().createChannel();
// 声明exchange中的消息为可持久化,不自动删除
// channel.exchangeDeclare(CommonConstants.EXCHANGE_NAME_DIRECT, BuiltinExchangeType.DIRECT, true, false, null);
channel.exchangeDeclare(CommonConstants.EXCHANGE_NAME_TOPIC, BuiltinExchangeType.TOPIC, true, false, null);
// 声明点赞的消息队列
// channel.queueDeclare(CommonConstants.QUERE_NAME_PRAISE, true, false, false, null);
// //绑定队列到交换机
// channel.queueBind(CommonConstants.QUERE_NAME_PRAISE, CommonConstants.EXCHANGE_NAME_DIRECT, CommonConstants.QUERE_KEY_PRAISE);
//
// // 声明收藏的消息队列
// channel.queueDeclare(CommonConstants.QUERE_NAME_COLLECT, true, false, false, null);
// //绑定队列到交换机
// channel.queueBind(CommonConstants.QUERE_NAME_COLLECT, CommonConstants.EXCHANGE_NAME_DIRECT, CommonConstants.QUERE_KEY_COLLECT);
channel.queueDeclare(CommonConstants.QUERE_NAME_NOTIFY, true, false, false, null);
channel.queueBind(CommonConstants.QUERE_NAME_NOTIFY, CommonConstants.EXCHANGE_NAME_TOPIC, CommonConstants.QUERE_KEY_NOTIFY);
channel.close();`而这个的运行是在listen之后的,导致一直在报bug。最后解决办法是:先手动注释listen的注解,声明exchange和queue之后,再重新运行代码。
标签:false,QUERE,记录,rabbitmqProperties,CommonConstants,RabbitMQ,解决,channel,NAME
From: https://www.cnblogs.com/coldcodeSJTU/p/18364448