3

I'm having trouble connecting to a RabbitMQ instance (it's my first time doing so). I've spun one up on AWS, and been given access to an admin panel which I'm able to access.

I'm trying to connect to the RabbitMQ server in python/pika with the following code:

import pika
import logging

logging.basicConfig(level=logging.DEBUG)

credentials = pika.PlainCredentials('*******', '**********')
parameters = pika.ConnectionParameters(host='a-25c34e4d-a3eb-32de-abfg-l95d931afc72f.mq.us-west-1.amazonaws.com',
                                       port=5671,
                                       virtual_host='/',
                                       credentials=credentials,
                                       )

connection = pika.BlockingConnection(parameters)

I get pika.exceptions.IncompatibleProtocolError: StreamLostError: ("Stream connection lost: ConnectionResetError(54, 'Connection reset by peer')",) when I run the above.

mcatoen
  • 111
  • 1
  • 6
  • You can verify the following 1) Check whether the port 5671 is accessible (Need make sure security groups are managed properly for achieving this) 2) Version check (Make sure the python library version you are using supports the version of rabbitmq running on AWS) – Santosh Balaji Selvaraj Jan 13 '21 at 08:50

1 Answers1

7

you're trying to connect through AMQP protocol and AWS is using AMQPS, you should add ssl_options to your connection parameters like this

import ssl

logging.basicConfig(level=logging.DEBUG)

credentials = pika.PlainCredentials('*******', '**********')
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
parameters = pika.ConnectionParameters(host='a-25c34e4d-a3eb-32de-abfg-l95d931afc72f.mq.us-west-1.amazonaws.com',
                                       port=5671,
                                       virtual_host='/',
                                       credentials=credentials,
                                       ssl_options=pika.SSLOptions(context)
                                       )

connection = pika.BlockingConnection(parameters)
Elduo
  • 86
  • 1
  • 4