I'm a data analyst and as part of one task we are getting data from a data provider using rabbitMQ. However, I am unable to get any data using the following code.
import ssl
import pika
credentials = pika.PlainCredentials("username", "password")
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
parameters = pika.ConnectionParameters(
host="host",
virtual_host="virtual host",
port=5671,
credentials=credentials,
ssl_options=pika.SSLOptions(context),
)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_consume(
queue="queue", on_message_callback=callback, auto_ack=True
)
print(" [*] Waiting for messages. To exit press CTRL+C")
try:
channel.start_consuming()
except KeyboardInterrupt:
connection.close()
finally:
connection.close()