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



我正在尝试通过SSL连接到ActiveMQ Amazon broker。我的应用程序是用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 broker,我以以下方式修改了代码:

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.异常。

请告知。

您当前正在通过URI传递用户凭据。但是,在URI引用文档中,我没有看到任何对usernamepassword的引用。此外,异常表示用户名为null这一事实表明URI中的用户凭据被忽略了。

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

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

相关内容

  • 没有找到相关文章

最新更新