本文介绍了如何使用rabbitmq-delayed-message-exchange插件在rabbitmq中发送延迟消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装了插件以从这里发送延迟消息 rabbitmq-delayed-message-交换.
I have installed the plugin to send a delayed message from here rabbitmq-delayed-message-exchange.
我找不到在 python 中使用它的任何帮助.我刚刚开始使用 rabbitmq .
I couldn't find any help for using it in python. I've just started using rabbitmq .
这是我一直在尝试的:
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.exchange_declare("test-x", type="x-delayed-message", arguments={"x-delayed-type":"direct"})
channel.queue_declare(queue='task_queue',durable=True)
channel.queue_bind(queue="task_queue", exchange="test-x", routing_key="task_queue")
channel.basic_publish(exchange='test-x',routing_key='task_queue',body='Hello World! Delayed',arguments={"x-delay":100})
print(" [x] Sent 'Hello World! Delayed'")
connection.close()
以下是列出的交易所:
sudo rabbitmqctl list_exchanges
Listing exchanges ...
amq.direct direct
test-x x-delayed-message
amq.fanout fanout
amq.match headers
amq.headers headers
direct
amq.rabbitmq.trace topic
amq.topic topic
amq.rabbitmq.log topic
我不知道如何将延迟参数传递给 basic_publish 函数
I don't have a good idea how I could pass a delay argument to the basic_publish function
感谢任何帮助
推荐答案
您需要将 x-delay
标头添加到您的消息属性中,并以毫秒为单位指定延迟值.试试这个:
You need to add the x-delay
header to your message properties and specify the delay value in milliseconds. Try this:
channel.basic_publish(
exchange='test-x',
routing_key='task_queue',
body='Hello World! Delayed',
properties=pika.BasicProperties(headers={"x-delay": 1000})
)
这篇关于如何使用rabbitmq-delayed-message-exchange插件在rabbitmq中发送延迟消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!