RabbitMQ C# 客户端不与 Apache Qpid Java Broker 对话

发布于 2024-07-14 22:33:30 字数 1316 浏览 3 评论 0 原文

我已在 Windows 机器上安装了 Apache Qpid Java 代理的 M4 版本,并使用开箱即用的配置(通过 qpid-server.bat 脚本)启动它。

我现在尝试使用 RabbitMQ C# 客户端库(版本 1.5.3,为 .NET 3.0 编译)将消息发布到队列; 我的代码是:

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "...";
    IProtocol protocol = Protocols.FromEnvironment();
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            string exchange = "...";
            string routingKey = "...";
            ch.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(message));
        }
    }
}

基本上,我不确定 factory.Parameters.VirtualHost 以及字符串 exchangeroutingKey 使用什么值。 我尝试了各种组合,但似乎没有任何效果 - 我所得到的最接近的是在 Qpid 服务器日志中看到以下内容:

2009-03-19 17:11:04,248 WARN  [pool-1-thread-1] queue.IncomingMessage (IncomingMessage.java:198) - MESSAGE DISCARDED: No routes for message - Message[(HC:896033 ID:1 Ref:1)]: 1; ref count: 1

看起来好像 Qpid 服务器正在接收消息,但不知道如何处理它。

任何关于我在客户端代码中需要什么配置值的建议(记住我在 virtualhosts.xml 中使用默认的 Qpid 配置)将不胜感激。 有关虚拟主机、交换器、队列和路由密钥以及 Qpid 如何将它们链接在一起的更多一般信息也将非常有用。

提前谢谢你,

艾伦

I've installed the M4 release of the Apache Qpid Java broker on a Windows box, and started it using the out-of-the-box configuration (via the qpid-server.bat script).

I'm now trying to publish a message to a queue using the RabbitMQ C# client library (version 1.5.3, compiled for .NET 3.0); my code is:

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "...";
    IProtocol protocol = Protocols.FromEnvironment();
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            string exchange = "...";
            string routingKey = "...";
            ch.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(message));
        }
    }
}

Basically, I'm unsure what values to use for factory.Parameters.VirtualHost and the strings exchange and routingKey. I've tried various combinations, but nothing seems to work - the closest I've got is seeing the following in the Qpid server log:

2009-03-19 17:11:04,248 WARN  [pool-1-thread-1] queue.IncomingMessage (IncomingMessage.java:198) - MESSAGE DISCARDED: No routes for message - Message[(HC:896033 ID:1 Ref:1)]: 1; ref count: 1

which looks as though the Qpid server is receiving the message, but doesn't know what to do with it.

Any advice on what configuration values I need in my client code (bearing in mind I'm using the default Qpid config in virtualhosts.xml) would be much appreciated. More general information on virtual hosts, exchanges, queues and routing keys, and how Qpid links them all together, would also be very useful.

Thank you in advance,

Alan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

冷血 2024-07-21 22:33:30

仅供参考,我最终成功了。 下面的代码向 localhost 虚拟主机上的 test.direct 交换中的队列 test-queue 发送一条消息(默认 Qpid 代理配置的所有部分):

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "/localhost";
    IProtocol protocol = Protocols.AMQP_0_8_QPID;
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            ch.ExchangeDeclare("test.direct", "direct");
            ch.QueueDeclare("test-queue");
            ch.QueueBind("test-queue", "test.direct", "TEST", false, null);
            ch.BasicPublish("test.direct", "TEST", null, Encoding.UTF8.GetBytes(message));
        }
    }
}

Just for reference, I managed to get this working in the end. The code below sends a message to the queue test-queue in the test.direct exchange on the localhost virtual host (all part of the default Qpid broker configuration):

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "/localhost";
    IProtocol protocol = Protocols.AMQP_0_8_QPID;
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            ch.ExchangeDeclare("test.direct", "direct");
            ch.QueueDeclare("test-queue");
            ch.QueueBind("test-queue", "test.direct", "TEST", false, null);
            ch.BasicPublish("test.direct", "TEST", null, Encoding.UTF8.GetBytes(message));
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文