问题描述
我有一个应用程序,我想在其中在 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);
这是我的接收器链接。如图所示,我设置了将提供给 ReceiverLink 的 Source 的 Durable uint。
因为正如我在 Active MQ Artemis 文档中看到的,Durable 是一个布尔值,但在 amqpnetlite 库中它是一个 uint,我的理解是所有超过 0 的内容都应该是真的,而 0 应该是假的。
起初的行为非常奇怪:即使当 Aretemis Web 界面显示为持久队列时,只要没有消费者连接,它就会被删除。
我发现了这个: ActiveMQ Artemis queue deleted after shutdown of consuming client 它描述了由于默认行为,即使是持久队列也会被删除。
所以我操作了 broker.xml 并将 auto-delete-QUEUE 设置为 false。
从那时起,行为完全改变了: 断开连接后,两个(持久 = 1 和持久 = 0)队列仍然存在。
那么如何正确创建持久连接和非持久连接?
解决方法
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"},};