Reputation: 411
Going through the Rabbit MQ Pika HelloWorld tutorial found here: https://www.rabbitmq.com/tutorials/tutorial-one-python.html
The problem is, I keep getting this error whenever I run my receive script:
Traceback (most recent call last):
File "receive.py", line 5, in <module>
pika.ConnectionParameters(host='localhost'))
File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 360, in __init__
self._impl = self._create_connection(parameters, _impl_class)
File "C:\Users\Colin Warn\PycharmProjects\untitled2\venv\lib\site-packages\pika\adapters\blocking_connection.py", line 451, in _create_connection
raise self._reap_last_connection_workflow_error(error)
pika.exceptions.AMQPConnectionError
Here's the code I'm attempting to run:
#!/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(
queue='hello', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
Any help is much appreciated. Thank you so much in advance.
Upvotes: 14
Views: 41397
Reputation: 5
I also faced the same issue. Then I enabled (open) the 5672 port in my hosting device. Then it solved.
Upvotes: 0
Reputation: 36
For me this problem arises when i updated my system.
And the possible reasons are either rabbitmq-server is not installed or rabbitmq-server is not running.
try to run the below command in ubuntu
sudo systemctl status rabbimtmq-server
if server is not running, use below command to start the server.
sudo systemctl restart rabbitmq-server
if everthing is fine, then your code will run without any problem.
In case if your are unable to start/restart the server, the re-install the rabbitmq from below link.
In my case, i solved the problem by reinstalling the rabbitmq.
Upvotes: 0
Reputation: 31
I get a different solution, instead of using host='localhost', use the rabbitmq docker container ipaddress (in my case it was 172.17.0.2), you can get that ip with the command:
docker inspect <container_id>
Upvotes: 3
Reputation: 1077
All you need to do is installing RabbitMQ in your PC. You can simply run with docker using the command below in another terminal, and re-run your code
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
Upvotes: 25
Reputation: 31
Follow these steps:
Upvotes: 3
Reputation: 411
You need to install RabbitMQ on your machine: https://rabbitmq.com/download.html
After installing RabbitMQ server re-run the script.
Upvotes: 6