1

我正在使用 Python3.6 连接到 RabbitMQ。此连接使用 TLSv1.2 协议。设置 SSL 的连接参数:

    cxt = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    ssl_options = pika.SSLOptions(context=cxt, server_hostname=rabbit_config['HOST'])

    conn_params = pika.ConnectionParameters(port=rabbit_config['PORT'],
                                            ssl_options=ssl_options,
                                            credentials=creds,
                                            virtual_host=rabbit_config['VIRTUAL_HOST'],
                                            channel_max=channel_size,
                                            heartbeat=heart_beat)

连接到 rabbitMq 时出现以下错误:

AMQPConnectionError: (AMQPConnectorSocketConnectError: ConnectionRefusedError(61, 'Connection refused'),)

我已经为Connection ParametersTLS params example推荐了 pika 文档,但到目前为止还没有成功。

连接到同一个 Rabbit 主机的类似代码在 Java 中工作:

    @Bean
    CachingConnectionFactory connectionFactory(String host,
            Integer port, String username,
            String password, boolean ssl,
             String sslAlgorithm) throws KeyManagementException, NoSuchAlgorithmException {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(host);
        connectionFactory.setPort(port);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        if (ssl) {
          connectionFactory.useSslProtocol();
          connectionFactory.useSslProtocol(sslAlgorithm);
        }

        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);
        cachingConnectionFactory.setRequestedHeartBeat(50);
        cachingConnectionFactory.setChannelCacheSize(10);
        return cachingConnectionFactory;
    }
4

1 回答 1

0

我很清楚为什么一定会发生这种情况,我处于类似的情况。如果您在与 rabbitmq 服务器相同的实例上运行您的代码,它可以工作吗?在 python 上使用 SSL 时,它似乎使用的是“guest”用户,因此它不允许本地主机之外的任何连接。如果是这种情况,请查看并尝试在同一实例上运行它。它应该工作。如果您单击此处,您可以查看我的问题,这非常相似,并且我已经在 localhost 上运行它。尝试从本地主机外部使用它时,我的问题仍然存在。

于 2019-08-22T11:27:30.027 回答