public function send($data, Config $config) { parent::send($data, $config); foreach ($this->container->get('grimkirill.queue.holder')->getConsumerList() as $id) { $condition = new ExecutionCondition(); $condition->setTimeout(1); $this->container->get($id)->execute($condition); } }
public function subscribe(Consumer $consumer, ExecutionCondition $condition) { $this->consumer = $consumer; $this->condition = $condition; $channel = $this->client->channel(); $channel->basic_consume($consumer->getConfig()->getDestination(), '', false, false, false, false, [$this, 'callback']); while ($condition->isValid()) { try { $channel->wait(null, null, 10); } catch (AMQPTimeoutException $e) { } } }
public function subscribe(Consumer $consumer, ExecutionCondition $condition) { if (array_key_exists($consumer->getConfig()->getDestination(), $this->messageList)) { $msgList = $this->messageList[$consumer->getConfig()->getDestination()]; foreach ($msgList as $key => $msg) { if ($condition->isValid()) { $condition->incrementMessagesCount(); $consumer->callback($msg['message']); unset($this->messageList[$consumer->getConfig()->getDestination()][$key]); } } } }
/** * @inheritdoc */ public function subscribe(Consumer $consumer, ExecutionCondition $condition) { $this->stompClient->subscribe($consumer->getConfig()->getDestination()); while ($condition->isValid()) { if ($message = $this->stompClient->readMessage(10)) { $condition->incrementMessagesCount(); $result = $consumer->callback($message->getBody()); if ($result) { $message->ack(); } else { $message->nack(); } } } }
protected function execute(InputInterface $input, OutputInterface $output) { if ($this->getContainer()->has($input->getArgument('handler'))) { $consumer = $this->getContainer()->get($input->getArgument('handler')); } else { $consumer = $this->getContainer()->get('queue.consumer.' . $input->getArgument('handler')); } $condition = new ExecutionCondition(); $condition->setTimeout($input->getOption('timeout')); if ($input->getOption('signal')) { $condition->enableSignal(); } $startTime = microtime(true); $consumer->execute($condition); if ($output->getVerbosity() > $output::VERBOSITY_VERBOSE) { $output->writeln('<info>Processed message count:</info> <comment>' . $condition->getMessagesCount() . '</comment>'); $output->writeln('<info>Processed message time:</info> <comment>' . round($consumer->getTotalWorkTime(), 3) . ' sec</comment>'); $output->writeln('<info>Total time:</info> <comment>' . round(microtime(true) - $startTime, 3) . ' sec</comment>'); } }