简体   繁体   中英

.Net AMQP client for IBM MQ

I am trying to connect to IBM MQ 9.0 using AMQP 1.0 channel from my .Net application.

The MQ Light portal currently supports Nodejs, ruby, java and python clients only. Do we have a MQ Light AMQP client for .Net?

I have tried connecting to IBM MQ 9 with Amqpnetlite client

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());
        }
    }
}

But I could not succeed in establishing a connection. When initiating the SenderLink, I am getting 2035 MQRC_NOT_AUTHORIZED exception. However, without changing any of the channel authentication in IBM MQ 9.0 Server, if I try it with MQ Light nodejs example (send.js), I am able to connect and send messages to AMQP channel.

Please suggest if there are any changes required in the above code.

Has anyone succeeded in establishing communication with IBM MQ with any other .Net 1.0 AMQP Clients? Need your help here. Thanks.

It seems that even when user name and password are not configured, the MQ broker requires SASL negotiation for the connection. You can enable SASL Anonymous on amqpnetlite as follows.

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();

It is also possible to do the same with 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM