【问题标题】:How to create a non durable queue in ActiveMQ Artemis?如何在 ActiveMQ Artemis 中创建非持久队列?
【发布时间】:2021-06-17 17:06:20
【问题描述】:

我有一个应用程序,我希望在 Active MQ Artemis 中有 1 个持久队列和 1 个非持久队列。 为了连接到这个消息总线,我使用 amqpnetlite。

        var source = new Source()
        {
        };

        if (durable)
        {
            source.Address = amqpAddressConverter.GetSubscriberAddress(address, useLoadBalancing);
            source.Durable = 1;
            source.ExpiryPolicy = new Symbol("never");
            source.DistributionMode = new Symbol("copy");
        }
        else
        {
            source.Address = amqpAddressConverter.GetSubscriberAddress(address);
            source.Durable = 0;
            source.ExpiryPolicy = "never";
        }

        var receiverLink = new ReceiverLink(session, linkName, source, null);

所以这是我的接收器链接。如图所示,我设置了 Source 的 Durable uint,它将提供给 ReceiverLink。

因为正如我在 Active MQ Artemis 文档中看到的那样,Durable 是一个布尔值,但在 amqpnetlite 库中,我的理解是超过 0 的所有内容都应该为真,而 0 应该为假。

一开始这种行为很奇怪:即使在 Aretemis Web 界面显示为持久队列时,只要没有连接消费者,它就会被删除。

我发现了这个: ActiveMQ Artemis queue deleted after shutdown of consuming client 它描述了由于默认行为,即使是持久队列也会被删除。

所以我操作了 broker.xml 并将 AUTO-DELETE-QUEUE 设置为 false。

从那时起,行为完全转变: 连接断开后,(durable = 1 和durable = 0)队列仍然存在。

那么如何正确创建持久连接和非持久连接呢?

【问题讨论】:

    标签: c# amqp activemq-artemis


    【解决方案1】:

    Artemis 源在 .NET 中带有一个 example,它创建了一个持久的主题订阅,并展示了如何在以后使用 AmqpNetLite 恢复它。

    许多人忽略的一个关键是您的客户端需要使用类似于 JMS 客户端 ID 概念的唯一容器 ID。

    对于特定于队列的订阅,客户端应在链接功能中指出它希望创建一个基于队列的地址,因为默认情况下是一个行为不同的多播队列。

    Source source = new Source() {
        Address = address,
        Capabilities = new Symbol[] {"queue"},
    };
    

    vs 特定主题的源配置:

    Source source = new Source() {
        Address = address,
        Capabilities = new Symbol[] {"topic"},
    };
    

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 2017-11-30
      • 2020-04-13
      • 2013-10-23
      • 2019-09-30
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 2020-04-24
      相关资源
      最近更新 更多