如何解决通过使用者回调函数_ python RabbitMQpika将消息发布到另一个队列
我想知道是否可以在Rabbit-MQ消费者回调函数中发布消息?
## publish function (publisher)
def publish_data(data):
channel.queue_declare(queue="another_queue")
channel.basic_publish(exchange='',routing_key="another_queue",body=json.dumps({
"message_title": data,}))
## the callback function we need to publish message to another queue
def consumer_callback(ch,method,properties,body):
publish_data(data="they said hi from another queue")
## consumer
def start_consumer():
channel.queue_declare(queue=queue)
channel.basic_consume(queue=queue,on_message_callback=consumer_callback,auto_ack=True)
channel.start_consuming()
start_consumer()
我写了上面的代码,但出现错误:
Stream connection lost: IndexError('pop from an empty deque')
raise exceptions.ChannelWrongStateError('Channel is closed.')
pika.exceptions.ChannelWrongStateError: Channel is closed.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。