Question

I'm trying to run the hello world version of using celery/rabbitmq (from rabbitmq site).

When I run python send.py it outputs this and throws an error:

python send.py
 [x] Sent 'Hello World!'
WARNING:pika.adapters.base_connection:Unknown state on disconnect: 0
WARNING:pika.adapters.base_connection:Unknown state on disconnect: 0

Here is my send.py :

#!/usr/bin/env python
import pika
import logging
logging.basicConfig()

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='xx.xxx.xx.xxx'))
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()

here is receive.py

#!/usr/bin/env python
import pika
import logging
logging.basicConfig()

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='xx.xxx.xx.xxx'))
channel = connection.channel()

channel.queue_declare(queue='hello')

print ' [*] Waiting for messages. To exit press CTRL+C'

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

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

channel.start_consuming()

EDIT (FIX): To not receive this warning of WARNING:pika.adapters.base_connection:Unknown state on disconnect: 0

Remove the connection.close() used in either send.py or receive.py files.

Was it helpful?

Solution

I'm not sure how celery is coming into play here, since you're just doing the RabbitMQ "Hello, world" tutorial, which has nothing to do with celery. But I believe those warnings are actually just caused by a bug in pika. It's not anything you're doing wrong with your example. See the bug report here: https://github.com/pika/pika/pull/346

Note that they're just warnings; they're being printed when connection.close() is called, and won't affect the behavior of the program at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top