【问题标题】:Unable to connect to RabbitMQ broker using amqps无法使用 amqps 连接到 RabbitMQ 代理
【发布时间】:2019-12-18 08:09:33
【问题描述】:

您好,我想使用 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 代理的指南/提示,我将不胜感激。

【问题讨论】:

    标签: rabbitmq amqp rabbitmq-exchange


    【解决方案1】:

    啊,我找到了解决方案。我在这里发布答案,希望对某人有所帮助:

    在 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

    【讨论】:

      猜你喜欢
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 2012-07-11
      相关资源
      最近更新 更多