3

I have installed pip install pika==0.11.0, as it is shown on the readme file, and after that I tried python receiver.py, and it gave me the following error:

Traceback (most recent call last):
File "receive.py", line 9, in <module>
channel.queue_declare(queue='hello')
File "C:\Python36\lib\site-packages\pika\adapters\blocking_connection.py", line 2400, in queue_declare
self._flush_output(declare_ok_result.is_ready)
File "C:\Python36\lib\site-packages\pika\adapters\blocking_connection.py", line 1258, in _flush_output
raise exceptions.ChannelClosed(method.reply_code, method.reply_text)
pika.exceptions.ChannelClosed: (406, "PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'false' but current is 'true'")

Even if I didn't modify anything. I tried also the spring-amqp example, and these works. Can you gave me a hint about what should I change?

These is the py fille:

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

The error is at thee following line:

 channel.queue_declare(queue='hello')
Vlad
  • 181
  • 3
  • 14

2 Answers2

4

The queue hello in the default vhost / already exists but it is declared as durable. Either delete this queue before you execute your code or declare it as durable from Python:

channel.queue_declare(queue='hello', durable=True)

See the section 'Message durability' of the tutorial.

0
# This script will publish MQ message to my_exchange MQ exchange

import pika
#credentials = pika.PlainCredentials('the_user', 'the_pass')
#connection = #pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', pika.PlainCredentials('guest', 'guest')))
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, 'test', pika.PlainCredentials('admin', 'password1243')))
channel = connection.channel()

#channel.queue_declare(queue='items-queue', durable=Ture)
channel.queue_declare(queue='dx-naas', durable=True)


channel.basic_publish(exchange='my-exchange', routing_key='my-routing-key', body='Hello World!')

print("[x] Sent 'Hello World!'")

connection.close()

devops-admin
  • 1,447
  • 1
  • 15
  • 26