Problem with getting data using RabbitMQ

32 views
Skip to first unread message

Petr Jániš

unread,
Jun 4, 2024, 5:08:46 AMJun 4
to rabbitmq-users
Hi all,

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()

Provider sees that I'm connected. Can you please help me? Thank you in advance.


Luke Bakken

unread,
Jun 4, 2024, 8:31:57 AMJun 4
to rabbitmq-users
Hello,

Your code looks fine, though you probably shouldn't be using auto_ack=True (https://www.rabbitmq.com/docs/confirms).

Are you certain you are consuming from the correct queue, and that messages are actually in it to be consumed?

It would be good to know what version of RabbitMQ you're connecting to, and what RabbitMQ writes to the log file when a connection is made.

You may be able to learn more by enabling debug logging -

Instead of INFO, use DEBUG. Save the output to a file and attach it to your response.

Thanks,
Luke
Reply all
Reply to author
Forward
0 new messages