| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /**
- * 通知的消费者
- * User: shish <shish@zhhinc.com>
- * Date: 2019/9/9 0009
- * Time: 14:54
- */
- namespace common\components\rabbitmq\consumer;
- use biz\message\services\InformAdminService;
- use biz\message\services\InformUserService;
- use mikemadisonweb\rabbitmq\components\ConsumerInterface;
- use PhpAmqpLib\Message\AMQPMessage;
- class InformConsumer implements ConsumerInterface
- {
- /**
- * @param AMQPMessage $msg
- * @return bool
- */
- public function execute(AMQPMessage $msg)
- {
- $data = unserialize($msg->body);
- //inform
- //$messageType = $data['messageType'];
- $userType = $data['userType'];
-
- if ($userType == 'user') {
- InformUserService::consumeInformQueue($data);
- }
- if ($userType == 'admin') {
- InformAdminService::consumeInformQueue($data);
- }
-
- if ($data['status'] == 200) {
- print_r('suceess ');
- return ConsumerInterface::MSG_ACK;
- } elseif ($data['status'] == 500) {
- sleep(5);
- print_r('faile ');
- return ConsumerInterface::MSG_REQUEUE;
- }
- /**
- * ConsumerInterface::MSG_ACK - Acknowledge message (mark as processed) and drop it from the queue
- * ConsumerInterface::MSG_REJECT - Reject and drop message from the queue
- * ConsumerInterface::MSG_REQUEUE - Reject and requeue message in RabbitMQ
- */
- }
-
- }
|