Spring Cloud 和 RabbitMQ:如何将队列更改为 auto-delete = false?
Spring Cloud and RabbitMQ: how change the queue to auto-delete = false?
我正在使用 Spring 云 example 和 RabbitMQ。
使用 RabbitMQ 启动 docker 之后:
sudo docker run -t -i --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
我执行了发布者和订阅者应用程序的示例来观察消息的行为。
我在管理面板 (http://localhost:15672) 中注意到的一件事是订阅服务器启动时创建的队列配置为 auto-delete: true
。因此,当没有订阅者 运行 时,不会创建队列,并且发布者发送的每条消息都会被 丢弃 。这不是我期望的默认配置!
所以,我想将创建的队列更改为 auto-delete: false
,因为这样消息就不会丢失,并且当某些订阅者启动时,它将能够使用排队的消息(对吗?)。我如何在 Spring?
上做到这一点
正如我所说,我使用的所有代码都可以在这个 example 中找到。我所做的唯一更改是将 Spring Boot 的版本更新为 1.5.9.RELEASE.
使用Spring Cloud Stream,the option使队列持久化是durableSubscription
:
spring.cloud.stream.rabbit.bindings.<channelName>.consumer.durableSubscription = true
正如解释的那样here:
depending on your needs, if you set it as an anonymous
consumer (no consumer group) then the queue will be automatically
deleted. This wouldn't work if you require multiple competing
consumers. If you do need a consumer group then you can use the
durableSubscription setting
我发现另一个有效的解决方案是:
spring.cloud.stream.bindings.<inputChanneName>.group=GROUP_NAME
我正在使用 Spring 云 example 和 RabbitMQ。
使用 RabbitMQ 启动 docker 之后:
sudo docker run -t -i --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
我执行了发布者和订阅者应用程序的示例来观察消息的行为。
我在管理面板 (http://localhost:15672) 中注意到的一件事是订阅服务器启动时创建的队列配置为 auto-delete: true
。因此,当没有订阅者 运行 时,不会创建队列,并且发布者发送的每条消息都会被 丢弃 。这不是我期望的默认配置!
所以,我想将创建的队列更改为 auto-delete: false
,因为这样消息就不会丢失,并且当某些订阅者启动时,它将能够使用排队的消息(对吗?)。我如何在 Spring?
正如我所说,我使用的所有代码都可以在这个 example 中找到。我所做的唯一更改是将 Spring Boot 的版本更新为 1.5.9.RELEASE.
使用Spring Cloud Stream,the option使队列持久化是durableSubscription
:
spring.cloud.stream.rabbit.bindings.<channelName>.consumer.durableSubscription = true
正如解释的那样here:
depending on your needs, if you set it as an anonymous consumer (no consumer group) then the queue will be automatically deleted. This wouldn't work if you require multiple competing consumers. If you do need a consumer group then you can use the durableSubscription setting
我发现另一个有效的解决方案是:
spring.cloud.stream.bindings.<inputChanneName>.group=GROUP_NAME