使用用户名和密码连接到Amazon ActiveMQ

时间:2018-12-06 10:28:12

标签: ssl activemq amazon broker

我正在尝试通过SSL连接到ActiveMQ Amazon经纪人。我的应用程序是用C#编写的。 以前,我通过TCP连接到localhost ActiveMQ代理,该代理有效:

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

要通过SSL连接到ActiveMQ Amazon代理,我已通过以下方式修改了代码:

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)
{            
}

但是,在启动连接后,会引发User name [null] or password is invalid.异常。

请告知。

1 个答案:

答案 0 :(得分:0)

您当前正在通过URI传递用户凭据。但是,在URI reference documentation中看不到对usernamepassword的引用。另外,该异常表示用户名为null的事实表明,您的URI中的用户凭据将被忽略。

相反,您应该按照here所述,在CreateConnection方法中传递用户凭据,例如:

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