我试图使用来自.Net应用程序的AMQP 1.0通道连接到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的通信?在这里需要您的帮助。谢谢。
看来,即使未配置用户名和密码,MQ代理也需要对连接进行SASL协商。您可以按以下步骤在amqpnetlite上启用SASL Anonymous。
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句