0

I wrote receiver as below:

import pika

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

ch.exchange_declare(exchange='ex1', exchange_type='fanout')
ch.queue_declare(queue='q1',exclusive=True)
ch.queue_bind(exchange='ex1',queue='q1')
print("wating for log")

def callback(ch, method, properties, body):
    print(f'This is from reciver {body}')
ch.basic_consume(queue='q1',on_message_callback=callback, auto_ack=True)
ch.start_consuming()

and i got this error when run it:

Traceback (most recent call last):
  File "receiver2.py", line 7, in <module>
    ch.queue_declare(queue='q1',exclusive=True)
  File "/train/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 2506, in queue_declare
    self._flush_output(declare_ok_result.is_ready)
  File "/train/lib/python3.8/site-packages/pika/adapters/blocking_connection.py", line 1339, in _flush_output
    raise self._closing_reason  # pylint: disable=E0702
pika.exceptions.ChannelClosedByBroker: (405, "RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'q1' in vhost '/'. It could be originally declared on another connection or the exclusive property value does not match that of the original declaration.")
Darwin
  • 1,695
  • 1
  • 19
  • 29

1 Answers1

1

I removed queue name(q1) in queue_declare

ch.queue_declare(queue='q1',exclusive=True)

to

ch.queue_declare(queue='',exclusive=True)
Darwin
  • 1,695
  • 1
  • 19
  • 29