rabbitmq - Spring boot RabbitMQ Listener Creating Duplicate Queue
问题描述
I have Two separate Applications, one is for producer and one is the consumer with exchange type Default(DIRECT).
Below is the configuration for Rabbit MQ Producer with Dead letter queue settings as well.
@Bean
Queue dlq() {
return QueueBuilder.durable(dlqQueueName).build();
}
@Bean
Queue queue() {
return QueueBuilder
.durable(queueName)
.withArgument("x-dead-letter-exchange", dlqExchange)
.withArgument("x-dead-letter-routing-key", deadLetterRoutingKey)
.withArgument("x-message-ttl",messageTTL)
.build();
}
@Bean
Binding binding() {
return BindingBuilder.bind(queue()).to(exchange()).with(routingkey);
}
@Bean
Binding dlqBinding() {
return BindingBuilder.bind(dlq()).to(deadLetterExchange()).with(deadLetterRoutingKey);
}
Now Here is the code for Rabbit MQ listener in a separate application.
@Component
public class RabbitMqConsumer implements MessageListener {
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "${queuename}", durable = "true"),
exchange = @Exchange(value = "exchange"),key = "routingkey"))
public void message(MyClass o) {
//save to db
}
@Override
public void onMessage(Message message) {
// TODO Auto-generated method stub
}
Now When I Run The consumer service, it creates a duplicate queue with same name. As shown in below picture
I also tried below setting in consumer but same result
@Bean
public Queue queue() {
return QueueBuilder
.durable(env.getProperty("queue"))
.ttl(ttl)
.deadLetterExchange(ddlE)
.deadLetterRoutingKey(env.getProperty("dle.routingkey"))
.build();
}
Note: This issue started to happen when I added dead letter queue settings in the producer, before this setting, I had this(mentioned below) bean
method in both configuration classes of consumer and producer and it was working fine.
@Bean
public Queue queue() {
return new Queue(queueName,true);
}
Any issues in above configuration? why its duplicating the queue, I could not figure it out just their features are different
Spring-boot-version : <version>2.5.2</version>
解决方案
您还没有共享属性文件!
您必须在属性文件中写入队列名称的末尾有一些隐藏字符或空格。
匹配消费者和生产者属性文件中的两个名称。应用程序之一(消费者或生产者)正在创建带有空格或隐藏字符的队列作为队列名称的一部分!
推荐阅读
- ios - 在目标上调用 xxx 时抛出无法识别的发送到实例的选择器
- mysql - 如何在mysql版本(6.0.11-alpha-community)中使用ISNULL函数
- r - 回答:R 基本错误 - 参数暗示不同的行数
- python - WM_Class 被忽略并且正在运行的应用程序的图标不与停靠/最喜欢的应用程序图标结合
- python - 破折号显示卡片边框和卡片标题之间的空白
- python - Python 3.x evdev 确定键盘和鼠标
- c# - 如何重构这些 switch case 以处理自然语言中的用户选择?
- outlook - 如何创建具有自定义值的 Outlook 日历事件?
- mysql - 如何选择仅按一个特定列分组的其他列的最大日期
- python - Lark 匹配自定义分隔符多行字符串