amazon-web-servicessslactivemq-classicbroker

Connecting to Amazon ActiveMQ with username & password


I'm trying to connect to ActiveMQ Amazon broker via SSL. My application is written in C#. Previously, I connected via TCP to localhost ActiveMQ broker, which worked:

using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Apache.NMS.ActiveMQ.Commands;


void Connect()
{       
    String brokerUri = "activemq:tcp://" + host + ":" + port + "? transport.useLogging=true&wireFormat.maxInactivityDuration=0&userName=myUsername&password=myPassword";
    NMSConnectionFactory factory = new NMSConnectionFactory(brokerUri);
    IConnection connection = factory.CreateConnection();
    connection.Start();
}

To connect to ActiveMQ Amazon broker via SSL, I have modified the code in the following way:

void Connect()
{
    String brokerUri = "ssl://" + host + ":" + port + "? transport.useLogging=true&wireFormat.maxInactivityDuration=0&userName=myUsername&password=myPassword";
    SslTransportFactory transportFactory = new SslTransportFactory();
    Uri uri = new Uri(brokerUri);
    ITransport transport = transportFactory.CreateTransport(uri);
    transport.Command = Command;
    transport.Exception = Exception;
    transport.Start();

    ConnectionFactory factory = new ConnectionFactory(brokerUri);
    IConnection connection = factory.CreateConnection();

    Connection con = (Connection)connection;
    con.ITransport = transport;

    con.Start();                  => Here the exception is thrown: User name [null] or password is invalid. 
}

private void Exception(ITransport sender, Exception command)
{            
}

private void Command(ITransport sender, Command command)
{            
}

However, upon starting the connection, User name [null] or password is invalid. Exception is thrown.

Please advise.


Solution

  • You're currently passing user credentials via the URI. However, I don't see any reference to username or password in the URI reference documentation. Also, the fact that the exception indicates the user name is null indicates the user credentials in your URI are simply being ignored.

    Instead you should pass the user credentials in the CreateConnection method as documented here, e.g.:

    IConnection connection = factory.CreateConnection("myUsername", "myPassword");