Search code examples
activemq-classicamqp

ActiveMQ Amqp C# ConnectionFactory and IConnectionFactory


I am using Amqp with ActiveMQ, which requires version 1-0-, not the old version 0-9-

In the version 0-9-* with "RabbitMQ.Client" (I was using RabbitMQ and switching to ActiveMQ), the following C# code works to connect to one broker.

factory = new ConnectionFactory()
                    {
                        Protocol = Protocols.FromEnvironment(),
                        HostName = IpAddress,
                        Port = Port,
                        VirtualHost = VirtualHost,
                        UserName = User,
                        Password = Password
                    };

but with version 1-0-* in "Apache.NMS.ActiveMQ", this does not work, (the example here use IConnectionFactory instead: http://activemq.apache.org/nms/examples.html but could not input HostName, Port, VirtualHost, UserName, Password there. )

How can I use "Apache.NMS.ActiveMQ", and do the connection with username, password in the code.

Thanks :)


Solution

  • ActiveMQ is a multi protocol broker. AMQP 1.0 is one of the wire protocols it supports.

    However, the Apache.NMS.ActiveMQ lib is using the OpenWire protocol (default port 61616 on AMQ). It's straight forward to connect using NMS to OpenWire, even with username and password.

    IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616);
    using (IConnection connection = factory.CreateConnection("user1234","s3cr3tp4ssw0rd")
    {
         using (ISession session = connection.CreateSession ()) 
         {
           // send a message or whatever
    

    If you really want to connect using AMQP, I suggest the QPid proton lib instead of NMS. NMS has something going on as well, but it's not there yet.