RABBITMQ的Spring -AMQP实施 - 它在内部使用Queuedeclarepassive吗?
我们从现有的经典队列迁移到法定人数,其中之一是我们必须将队列用法宣布为“被动”(即QueuedeclarePassive)。目的是确保我们不会动态创建任何队列,而只检查其存在(如果不存在,则失败)然后连接。
我们有一项使用Spring-AMQP的旧服务,我们将SimpleMessageListenerContainer设置为这样:
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(queue().getName());
...
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
return rabbitTemplate;
}
我看不到将队列声明为“被动”的方法。在阅读spring.io文档时,我看到了声明的描述:
“被动队列声明失败时重试的尝试数量。当消费者启动消费者或从多个队列中消费时,就会发生被动队列声明,当并非所有队列都可以在多个队列中消费时初始化。”
这是否意味着Spring-AMQP在幕后使用queuedeclarepassive?这是否在任何地方都有明确的记录?如果我不正确,如何在此AMQP使用中正确确保使用queuedeclarepassive?
提前致谢!
We are migrating from existing classic queues to quorum queues and one of the requirements is that we must declare queue usage as "passive" (i.e. queueDeclarePassive). The intent is to ensure we do not create any queues dynamically and only check for its existence (and fail if it doesn't exist) and then connect.
We have a legacy service that uses spring-amqp and we set the SimpleMessageListenerContainer like so:
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(queue().getName());
...
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.getConnectionFactory().createConnection().createChannel(false);
return rabbitTemplate;
}
I don't see a way to declare the queue as "passive". In reading the spring.io documentation, I see a description for declarationRetries:
"The number of retry attempts when passive queue declaration fails. Passive queue declaration occurs when the consumer starts or, when consuming from multiple queues, when not all queues were available during initialization."
Does this imply that spring-amqp uses queueDeclarePassive behind the scenes? Is this explicitly documented anywhere? If I'm incorrect, how do I properly ensure queueDeclarePassive is used within this amqp usage?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是暗示它明确说明它。
queuedeclarepassive
在启动过程中使用了侦听器容器,以验证已配置的队列。默认情况下,
SimpleMessageListenerContainer
将以5秒的间隔尝试3次,如果被动声明失败,则容器将停止。可以配置尝试和间隔的数量。DirectMessageListEnerContainer
使用其Monitor> Monitor> Monitor> Monitalval
属性,将无限期地尝试被动声明队列。Spring AMQP仅执行非邮局队列声明(队列创建),如果应用程序上下文包含
Queue
@Bean
s,并且有一个Rabbitadmin
< < 代码> @bean 存在。It doesn't imply it, it explicitly states it.
queueDeclarePassive
is used by the listener containers during startup to verify the configured queue(s) are present.By default, the
SimpleMessageListenerContainer
will try 3 times at 5 second intervals, and if the passive declarations fail, the container will stop. The number of attempts and interval can be configured.The
DirectMessageListenerContainer
will try indefinitely to passively declare the queue(s) if they don't exist, using itsmonitorInterval
property.Spring AMQP will only perform non-passive queue declaration (queue creation) if the application context contains
Queue
@Bean
s and there is aRabbitAdmin
@Bean
present.