【问题标题】:.Net AMQP client for IBM MQIBM MQ 的 .Net AMQP 客户端
【发布时间】:2016-12-14 03:42:48
【问题描述】:

我正在尝试使用 AMQP 1.0 通道从我的 .Net 应用程序连接到 IBM MQ 9.0。

MQ Light 门户目前仅支持 Nodejs、ruby、java 和 python 客户端。我们有 .Net 的 MQ Light AMQP 客户端吗?

我尝试使用 Amqpnetlite 客户端连接到 IBM MQ 9

namespace AMQPNetLiteSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Start");
            //Address addr = new Address("10.58.139.97", 1234, "Username","password", "/", "AMQP");
            Address addr = new Address("amqp://10.58.139.97:1234");

            Connection con = new Connection(addr);
            con.Closed += con_Closed;
            Console.WriteLine("Created connection");

            Session session = new Amqp.Session(con);
            session.Closed += session_Closed;
            Console.WriteLine("Created session");

            SenderLink link = new SenderLink(session, "sender_12565455877", "/public");
            Console.WriteLine("Created link");
            var message = new Message();
            message.Properties = new Properties();
            message.Properties.Subject = "mysamplemsg";
            message.ApplicationProperties = new ApplicationProperties();
            message.ApplicationProperties["myprop"] = "Hello World";
            Console.WriteLine("sending message");
            link.Send(message);

        }

        static void session_Closed(AmqpObject sender, Error error)
        {
            Console.WriteLine("Session closed");
            Console.WriteLine(error.ToString());
        }

        static void con_Closed(AmqpObject sender, Error error)
        {
            Console.WriteLine("Connection closed");
            Console.WriteLine(error.ToString());
        }
    }
}

但我无法成功建立连接。启动 SenderLink 时,我收到 2035 MQRC_NOT_AUTHORIZED 异常。 但是,在不更改 IBM MQ 9.0 Server 中的任何通道身份验证的情况下,如果我使用 MQ Light nodejs 示例 (send.js) 进行尝试,我可以连接并向 AMQP 通道发送消息。

请建议上述代码是否需要任何更改。

是否有人成功地与任何其他 .Net 1.0 AMQP 客户端建立了与 IBM MQ 的通信?在这里需要你的帮助。谢谢。

【问题讨论】:

  • 理论上任何 AMQP 客户端都应该工作。您可以在 MQ 队列管理器的错误日志中找到有关 NO_AUTHORIZED 原因的详细信息。 (AMKERR01.LOG)

标签: .net node.js ibm-mq amqp


【解决方案1】:

似乎即使没有配置用户名和密码,MQ 代理也需要 SASL 协商才能进行连接。您可以在 amqpnetlite 上启用 SASL 匿名,如下所示。

Address address = new Address("amqp://10.58.139.97:1234");
Connection connection = new Connection(address, SaslProfile.Anonymous, null, null);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-12345", "/public");
Message message = new Message("Hello");
message.Properties = new Properties() { MessageId = "msg", To = "q1" };
sender.Send(message);
connection.Close();

也可以对 ConnectionFactory 做同样的事情。

Address address = new Address("amqp://10.58.139.97:1234");
var factory = new ConnectionFactory();
factory.SASL.Profile = SaslProfile.Anonymous;
Connection connection = await factory.CreateAsync(address);

【讨论】:

  • 您应该在您的 GitHub 站点上发布此示例代码。当前的示例代码没有提到这个要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-03
  • 2011-02-09
  • 2011-07-22
  • 2022-11-08
  • 2014-02-11
  • 2020-05-14
  • 2015-01-09
相关资源
最近更新 更多