/** * Configure queue. */ private function configureQueue() { $this->queue = Queue::getInstance(); $this->queue->addListener(QueueEvents::RECEIVED, array($this, 'received')); $this->queue->addListener(QueueEvents::STARTED, array($this, 'started')); $this->queue->addListener(QueueEvents::HALTED, array($this, 'halted')); }
/** * {@inheritdoc} */ public function dispatch(MessageInterface $command) { if (!$command instanceof CommandInterface) { throw new InvalidArgumentException(sprintf('Command "%s" should implement \\Borobudur\\Cqrs\\Message\\CommandInterface', get_class($command))); } if ($command instanceof JobInterface && $command->isQueued()) { Queue::getInstance()->send(new QueueMessage($command)); return null; } return $this->dispatchNow($command); }
/** * {@inheritdoc} */ public function receive($channel = null, &$message) { $channel = Queue::formatChannel($channel); $id = $this->redis->blPop($channel, 10); $message = $this->redis->hGetAll($this->formatId($id)); if (empty($message)) { $message = null; return true; } $message = unserialize($message['payload']); $this->redis->del($this->formatId($id)); return true; }