我正在尝试使用来自我的.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的通信?需要你的帮助。感谢。
答案 0 :(得分:3)
即使未配置用户名和密码,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);