RABBITMQ的Spring -AMQP实施 - 它在内部使用Queuedeclarepassive吗?

发布于 2025-01-23 00:53:14 字数 1070 浏览 2 评论 0原文

我们从现有的经典队列迁移到法定人数,其中之一是我们必须将队列用法宣布为“被动”(即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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2025-01-30 00:53:14

这是否暗示Spring-AMQP在幕后使用Queuedeclarepassive?

它不是暗示它明确说明它。

queuedeclarepassive在启动过程中使用了侦听器容器,以验证已配置的队列。

默认情况下,SimpleMessageListenerContainer将以5秒的间隔尝试3次,如果被动声明失败,则容器将停止。可以配置尝试和间隔的数量。

DirectMessageListEnerContainer使用其Monitor> Monitor> Monitor> Monitalval属性,将无限期地尝试被动声明队列。

Spring AMQP仅执行非邮局队列声明(队列创建),如果应用程序上下文包含Queue @Bean s,并且有一个Rabbitadmin < < 代码> @bean 存在。

Does this imply that spring-amqp uses queueDeclarePassive behind the scenes?

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 its monitorInterval property.

Spring AMQP will only perform non-passive queue declaration (queue creation) if the application context contains Queue @Beans and there is a RabbitAdmin @Bean present.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文