1

I am using Python3.6 to get connection to RabbitMQ. This connection uses TLSv1.2 protocol. Setting the connection parameters for 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)

Getting following error when connecting to rabbitMq:

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

I have referred pika docs for Connection Parameters, and TLS params example, but no success so far.

The similar code to connect to same Rabbit host is woriking in 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;
    }
Nitin1706
  • 621
  • 1
  • 11
  • 21

1 Answers1

0

I have a good idea why this must be happening, I am in a similar situation. If you run your code on the same instance as the rabbitmq server, does it work? When using SSL over python it seems to be using the "guest" user and so it doesn't allow any connections outside of localhost. If this is the case, have a look and try running it on the same instance. It should work. If you click here you can have a look at my problem which is quite similar, and I have got it working on localhost. My problem persists when trying to use it from outside the localhost.

DUDANF
  • 2,618
  • 1
  • 12
  • 42