InformConsumer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * 通知的消费者
  4. * User: shish <shish@zhhinc.com>
  5. * Date: 2019/9/9 0009
  6. * Time: 14:54
  7. */
  8. namespace common\components\rabbitmq\consumer;
  9. use biz\message\services\InformAdminService;
  10. use biz\message\services\InformUserService;
  11. use mikemadisonweb\rabbitmq\components\ConsumerInterface;
  12. use PhpAmqpLib\Message\AMQPMessage;
  13. class InformConsumer implements ConsumerInterface
  14. {
  15. /**
  16. * @param AMQPMessage $msg
  17. * @return bool
  18. */
  19. public function execute(AMQPMessage $msg)
  20. {
  21. $data = unserialize($msg->body);
  22. //inform
  23. //$messageType = $data['messageType'];
  24. $userType = $data['userType'];
  25. if ($userType == 'user') {
  26. InformUserService::consumeInformQueue($data);
  27. }
  28. if ($userType == 'admin') {
  29. InformAdminService::consumeInformQueue($data);
  30. }
  31. if ($data['status'] == 200) {
  32. print_r('suceess ');
  33. return ConsumerInterface::MSG_ACK;
  34. } elseif ($data['status'] == 500) {
  35. sleep(5);
  36. print_r('faile ');
  37. return ConsumerInterface::MSG_REQUEUE;
  38. }
  39. /**
  40. * ConsumerInterface::MSG_ACK - Acknowledge message (mark as processed) and drop it from the queue
  41. * ConsumerInterface::MSG_REJECT - Reject and drop message from the queue
  42. * ConsumerInterface::MSG_REQUEUE - Reject and requeue message in RabbitMQ
  43. */
  44. }
  45. }