/** * @inheritdoc */ public function process(EnvelopeInterface $envelope) { try { $result = $this->processor->process($envelope); } catch (\Exception $exception) { $this->logger->error($exception->getMessage(), ['message' => $envelope->getDeliveryTag()]); $this->logger->debug($exception->getTraceAsString()); $result = $this->retryMessage($envelope, $exception); } return $result; }
/** * @param QueueInterface $queue * @param ProcessorInterface $processor * @param EventDispatcherInterface $dispatcher */ public function __construct(QueueInterface $queue, ProcessorInterface $processor, EventDispatcherInterface $dispatcher = null) { $this->queue = $queue; $this->processor = $processor; $this->dispatcher = $dispatcher ?: new EventDispatcher(); $this->setCallback(function (EnvelopeInterface $envelope) { try { $event = new ConsumeEvent($envelope); $this->dispatcher->dispatch(QueueEvents::CONSUME_MESSAGE, $event); $result = $this->processor->process($envelope); $event->setResult($result); $this->dispatcher->dispatch(QueueEvents::CONSUMED_MESSAGE, $event); $this->ack($envelope); return $event->shouldContinueConsuming(); } catch (\Exception $exception) { $this->dispatcher->dispatch(QueueEvents::CONSUME_EXCEPTION, new ConsumeExceptionEvent($envelope, $exception)); $this->nack($envelope, $this->nackRequeue); throw $exception; } }); }