嗨,我想使用amqps连接到Rabbitmq代理,但是似乎无法正常工作。
ConnectionFactory cf = new ConnectionFactory();
Uri uri = new Uri("amqps://localhost:5671");
cf.Uri = uri;
我已经启用了插件“ rabbitmq_auth_mechanism_ssl”,并将rabbitmq.conf配置为以下内容:
management.tcp.port = 15672
management.ssl.port = 15671
management.ssl.cacertfile = C:\\CA\\ca.cert.pem
management.ssl.certfile = C:\\CA\\serca.cert.pem
management.ssl.keyfile = C:\\CA\\private.key.pem
listeners.ssl.1 = 5671
ssl_options.cacertfile = C:\\CA\\ca.cert.pem
ssl_options.certfile = C:\\CA\\serca.cert.pem
ssl_options.keyfile = C:\\CA\\private.key.pem
ssl_options.password = secret
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = true
auth_mechanisms.1 = EXTERNAL
auth_mechanisms.2 = PLAIN
auth_mechanisms.3 = AMQPLAIN
我是否需要再次启用另一个插件才能使其工作?
如果有人能给我一些使用amqps与RabbitMQ代理建立连接的指南/提示,我将不胜感激。
答案 0 :(得分:0)
啊,我找到了解决方案。我将答案发布在这里,希望对您有所帮助。
在C#中:
ConnectionFactory cf = new ConnectionFactory();
Uri uri = new Uri("amqps://sample:sample@localhost");
cf.Port = AmqpTcpEndpoint.DefaultAmqpSslPort;
cf.Uri = uri;
var sslOptions = new SslOption
{
Enabled = true,
ServerName = "server cn",
AcceptablePolicyErrors = System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors |
System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch |
System.Net.Security.SslPolicyErrors.RemoteCertificateNotAvailable,
};
cf.Ssl = sslOptions;
在Rabbitmq.conf中
management.tcp.port = 15672
management.ssl.port = 15671
management.ssl.cacertfile = C:\\CA\\ca.cert.pem
management.ssl.certfile = C:\\CA\\serca.cert.pem
management.ssl.keyfile = C:\\CA\\private.key.pem
listeners.ssl.1 = 5671
ssl_options.cacertfile = C:\\CA\\ca.cert.pem
ssl_options.certfile = C:\\CA\\serca.cert.pem
ssl_options.keyfile = C:\\CA\\private.key.pem
ssl_options.password = secret
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = false <<<< need to set this to false.
auth_mechanisms.1 = EXTERNAL
auth_mechanisms.2 = PLAIN
auth_mechanisms.3 = AMQPLAIN
参考: https://www.squaremobius.net/amqp.node/ssl.html
http://rabbitmq.1065348.n5.nabble.com/C-client-connect-using-SSL-td31134.html