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]); } } } }
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) { } } }
/** * @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(); } } } }