Mmoreram\RSQueueBundle\Command\SubscriberCommand::execute PHP Method

execute() protected method

Execute code.
protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface An InputInterface instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        /**
         * Define all channels this command must listen to
         */
        $this->define();
        $serializer = $this->getContainer()->get('rs_queue.serializer');
        $resolver = $this->getContainer()->get('rs_queue.resolver.queuealias');
        $eventDispatcher = $this->getContainer()->get('event_dispatcher');
        $methods = $this->methods;
        $channelAliases = array_keys($methods);
        $channels = $resolver->getQueues($channelAliases);
        if ($this->shuffleQueues()) {
            shuffle($channels);
        }
        $this->getContainer()->get('rs_queue.redis')->subscribe($channels, function ($redis, $channel, $payloadSerialized) use($methods, $resolver, $serializer, $eventDispatcher, $input, $output) {
            $channelAlias = $resolver->getQueueAlias($channel);
            $method = $methods[$channelAlias];
            $payload = $serializer->revert($payloadSerialized);
            /**
             * Dispatching subscriber event...
             */
            $subscriberEvent = new RSQueueSubscriberEvent($payload, $payloadSerialized, $channelAlias, $channel, $redis);
            $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);
        });
    }
SubscriberCommand