延迟插件实现延迟队列

原创Michael_曾浩 最后发布于2016-10-20 14:10:26 阅读数 2456 收藏
展开
环境要求
Github:
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange
Rabbitmq版本要求: RabbitMQ 3.5.7 and later versions.
Erlang版本要求: Erlang/OTP 18.0 and later versions
插件列表:
http://www.rabbitmq.com/community-plugins.html
延迟插件下载地址:
https://bintray.com/rabbitmq/community-plugins/rabbitmq_delayed_message_exchange/v3.6.x#files

安装
拷贝rabbitmq_delayed_message_exchange到plugins
启动插件:
rabbitmq-plugins enable rabbitmq_delayed_message_exchange

Rabbitmq设置


测试结果


生产者代码
# encoding: utf-8
import pika, time

'''创建rabbitmq连接'''
credentials = pika.PlainCredentials("michael", "michael")
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='192.168.12.171', credentials=credentials))


delay_channel = connection.channel()
'''发送消息确认'''
delay_channel.confirm_delivery()

'''消息延迟时间(ms)'''
headers = {
"x-delay": 10000
}
delay_channel.basic_publish(exchange='delay',
routing_key='delay',
body=str( time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))),
properties=pika.BasicProperties(headers=headers, delivery_mode=2))

print " [x] Sent"
————————————————
版权声明:本文为CSDN博主「Michael_曾浩」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_29778131/java/article/details/52872097

posted on 2020-04-02 17:50  枫飞飞  阅读(249)  评论(0编辑  收藏  举报