【问题标题】:Sending Queue Message on Artemis using C#使用 C# 在 Artemis 上发送队列消息
【发布时间】:2020-01-01 07:34:18
【问题描述】:

我实际上是在尝试使用 C# 在 Artemis 上发送队列消息。 正在创建一个实例,但不是我想要的,当我检查队列消息时,它显示为 0。我还想添加一个到期日期并将 Routing_Type 设置为 ANYCAST,但看不到在哪里指定这些详细信息。

在我的实际代码下方找到,我尝试将到期日期设置为 5 分钟;

        private static void SendMsgAtemis()
        {
            string address = "amqp://tst01sacmamq.corporate.intra:61616";

            Connection connection = new Connection(new Address(address));
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "test-sender", "Nad-Test");

            Message message1 = new Message("Hello AMQP!");
            TimeSpan ts = new TimeSpan(0, 5, 0);
            sender.Send(message1, ts);


            Console.WriteLine("Message sent into queue Nad-Test");
        }

上面运行时,实例正在创建中,但是可以看到,Queue消息显示为0;

任何人都可以就上述问题提出建议吗? Nad-Test 已创建,但没有队列计数,它处于 MultiCast 模式。

【问题讨论】:

  • 您是在您的broker.xml 中配置了Nad-Test 地址还是代理为您自动创建的?
  • @JustinBertram 它是在我发送消息时创建的。

标签: c# activemq-artemis sender


【解决方案1】:

使用 ActiveMQ Artemis 的 .NET 客户端,应该就这么简单:

var connectionFactory = new ConnectionFactory();
var endpoint = Endpoint.Create("tst01sacmamq.corporate.intra", 61616);
var connection = await connectionFactory.CreateAsync(endpoint);

var producer = await connection.CreateProducerAsync("Nad-Test", RoutingType.Anycast);
var msg = new Message("Hello AMQP!")
{
    TimeToLive = TimeSpan.FromMinutes(5)
};
await producer.SendAsync(msg);

此客户端基于 AmqpNetLite,但它会为您处理所有 ActiveMQ Artemis 细节。

https://www.nuget.org/packages/ArtemisNetClient

https://havret.github.io/dotnet-activemq-artemis-client/

【讨论】:

    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 2013-12-16
    • 2019-08-16
    • 2017-02-07
    • 2013-01-16
    • 2020-04-05
    相关资源
    最近更新 更多