Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMq Connection to 127.0.0.1:5672 Failed

I'm currently following a rabbitmq tutorial and running into an issue. No matter how close I follow the tutorial I keep getting this error when trying to run my send.py and receive.py:

pika.exceptions.ConnectionClosed: Connection to 127.0.0.1:5672 failed: [Errno 61] Connection refused

This is the send.py:

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()

This is the receive.py:

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

I can't for the life of me figure out what I'm doing wrong. I've looked at other post on here that ask a similar question but still no dice.

like image 650
Edsel Norwood Avatar asked Oct 14 '25 03:10

Edsel Norwood


1 Answers

I used the same tutorial it seems, and they did miss the dependency to install and run rabbitmq

After doing brew install rabbitmq and then brew services start rabbitmq the connection to localhost on Pika then works

like image 180
Brandon M Warech Avatar answered Oct 16 '25 15:10

Brandon M Warech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!