Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program Running Pika Throwing AMQPConnectionError

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.

like image 490
Colin Warn Avatar asked Dec 08 '22 12:12

Colin Warn


2 Answers

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
like image 56
Susaj S N Avatar answered Dec 19 '22 21:12

Susaj S N


You need to install RabbitMQ on your machine: https://rabbitmq.com/download.html

After installing RabbitMQ server re-run the script.

like image 41
Colin Warn Avatar answered Dec 19 '22 22:12

Colin Warn