赞
踩
大部分介绍的rabbitmq都是利用ttl与死信的方式,rabbitmq提供的插件rabbitmq_delayed_message_exchange可以很好的实现延迟消息的功能,找了半天,网上居然没有php的例子,继而摸索了一下,参考了java的代码,总结如下:
安装流程:
下载 wget https://dl.bintray.com/rabbitmq/community-plugins/3.6.x/rabbitmq_delayed_message_exchange/rabbitmq_delayed_message_exchange-20171215-3.6.x.zip
解压 unzip rabbitmq_delayed_message_exchange-20171215-3.6.x.zip
移动到插件目录 mv rabbitmq_delayed_message_exchange-20171215-3.6.x.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.6.15/plugins/
启动 rabbitmq-plugins enable rabbitmq_delayed_message_exchange
对于代码来讲,首先对于发布者核心变化的代码
- $ex = new \AMQPExchange($channel);
- $ex->setName($e_name);
- $ex->setType('x-delayed-message');
- $ex->setArgument('x-delayed-type','direct');
- $ex->publish($message, $k_route,AMQP_NOPARAM,['headers' => ['x-delay
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。