Esempio n. 1
0
 /**
  * Execute code.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output) : int
 {
     /*
      * Define all channels this command must listen to
      */
     $this->define();
     $channelAliases = array_keys($this->methods);
     $channels = $this->queueAliasResolver->getQueues($channelAliases);
     if ($this->shuffleQueues()) {
         shuffle($channels);
     }
     $this->redis->subscribe($channels, function ($redis, $channel, $payloadSerialized) use($input, $output) {
         $channelAlias = $this->queueAliasResolver->getQueue($channel);
         $method = $this->methods[$channelAlias];
         $payload = $this->serializer->revert($payloadSerialized);
         /*
          * Dispatching subscriber event...
          */
         $subscriberEvent = new RSQueueSubscriberEvent($payload, $payloadSerialized, $channelAlias, $channel, $redis);
         $this->eventDispatcher->dispatch(RSQueueEvents::RSQUEUE_SUBSCRIBER, $subscriberEvent);
         /*
          * All custom methods must have these parameters
          *
          * InputInterface  $input   An InputInterface instance
          * OutputInterface $output  An OutputInterface instance
          * Mixed           $payload Payload
          */
         $this->{$method}($input, $output, $payload);
     });
     return 0;
 }
Esempio n. 2
0
 /**
  * Execute code.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output) : int
 {
     $this->define();
     $patterns = array_keys($this->methods);
     if ($this->shuffleQueues()) {
         shuffle($patterns);
     }
     $this->redis->psubscribe($patterns, function ($redis, $pattern, $channel, $payloadSerialized) use($input, $output) {
         $payload = $this->serializer->revert($payloadSerialized);
         $method = $this->methods[$pattern];
         /*
          * All custom methods must have these parameters
          *
          * InputInterface  $input   An InputInterface instance
          * OutputInterface $output  An OutputInterface instance
          * Mixed           $payload Payload
          */
         $this->{$method}($input, $output, $payload);
     });
     return 0;
 }