TransferService.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\main\service;
  3. use app\main\constants\MqConstants;
  4. class TransferService extends BaseService {
  5. const EXCHANGE_NAME ='cps.ex.topic';
  6. private $map = [];
  7. private static $route_key = null;
  8. /**
  9. * @var TransferService
  10. */
  11. protected static $self = null;
  12. /**
  13. * @return BaseService|TransferService
  14. */
  15. public static function instance()
  16. {
  17. if (self::$self == NULL) {
  18. self::$self = new self();
  19. }
  20. return self::$self;
  21. }
  22. //粉丝备份
  23. public function setBackups($id,$next = null){
  24. $this->map = [
  25. 'id' => $id,
  26. 'next' => $next
  27. ];
  28. self::$route_key = MqConstants::CHANNEL_FANS_BACKUPS;
  29. return $this;
  30. }
  31. //粉丝转移
  32. public function setTransfer($id,$next = null){
  33. $this->map = [
  34. 'id' => $id,
  35. 'next' => $next
  36. ];
  37. self::$route_key = MqConstants::CHANNEL_FANS_TRANSFER;
  38. return $this;
  39. }
  40. /**
  41. * 推送MQ消息
  42. */
  43. public function push(){
  44. $mq = MqService::instance()->getDotMqInstance();
  45. $mq->transferExchange($this->map, self::EXCHANGE_NAME, self::$route_key, 'topic');
  46. }
  47. }