gpt4 book ai didi

AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - 自动创建多消费者多播队列

转载 作者:行者123 更新时间:2023-12-03 23:15:36 27 4
gpt4 key购买 nike

这个问题是在 .Net 中使用 AMQP 来消费消息。文档推荐使用 amqpnetlite:https://access.redhat.com/documentation/en-us/red_hat_amq/7.0/html-single/using_the_amq_.net_client/index

使用 AMQPNetLite 订阅地址时,将自动创建地址和队列。不过,自动创建的队列始终是“单播”的。我无法自动创建

  • 多播队列
  • 这允许任意数量的消费者。

  • 代码:
    private async Task RenewSession()
    {
    Connect = await Connection.Factory.CreateAsync(new Address("amqp://admin:admin@localhost:5672"), new Open() {ContainerId = "client-1"});
    MqSession = new Session(Connect);
    var receiver = new ReceiverLink(MqSession, DEFAULT_SUBSCRIPTION_NAME, GetSource("test-topic"), null);
    receiver.Start(100, OnMessage);
    }

    private Source GetSource(string address)
    {
    var source = new Source
    {
    Address = address,
    ExpiryPolicy = new Symbol("never"),
    Durable = 2,
    DefaultOutcome = new Modified
    {
    DeliveryFailed = true,
    UndeliverableHere = false
    }
    };
    return source;
    }

    也许我错过了一些标志?

    最佳答案

    在 AMQP 中,您可以通过设置功能在自动创建队列(任播路由)或主题(多播路由)之间进行选择。

    能力应该是 new Symbol("queue")new Symbol("topic") .

    public class SimpleAmqpTest
    {
    [Fact]
    public async Task TestHelloWorld()
    {
    Address address = new Address("amqp://guest:guest@localhost:5672");
    Connection connection = await Connection.Factory.CreateAsync(address);
    Session session = new Session(connection);

    Message message = new Message("Hello AMQP");

    Target target = new Target
    {
    Address = "q1",
    Capabilities = new Symbol[] { new Symbol("queue") }
    };

    SenderLink sender = new SenderLink(session, "sender-link", target, null);
    await sender.SendAsync(message);

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

    ReceiverLink receiver = new ReceiverLink(session, "receiver-link", source, null);
    message = await receiver.ReceiveAsync();
    receiver.Accept(message);

    await sender.CloseAsync();
    await receiver.CloseAsync();
    await session.CloseAsync();
    await connection.CloseAsync();
    }
    }

    看看 https://github.com/Azure/amqpnetlite/issues/286 ,代码来自哪里。

    您可以通过设置 default-address-routing-type 来选择默认路由是多播还是任播。在 broker.xml 中,所有内容都记录在 https://activemq.apache.org/artemis/docs/2.6.0/address-model.html

    经纪人的 multicastPrefixanycastPrefix未为 AMQP 实现功能。 https://issues.jboss.org/browse/ENTMQBR-795

    关于AMQPNETLITE - ActiveMQ Artemis (Red Hat AMQ) - 自动创建多消费者多播队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51579188/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com