/** * @inheritdoc */ public function retry(EnvelopeInterface $envelope, $attempt, \Exception $exception = null) { // decrease priority with every attempt $priority = $envelope->getPriority(); if ($priority > 0) { --$priority; } $message = $this->createRetryMessage($envelope, $attempt, $exception); $message->setPriority($priority); return $this->publisher->publish($message); }
/** * Creates a new message to retry. * * @param EnvelopeInterface $envelope * @param int $attempt * @param \Exception $exception * * @return Message */ protected function createRetryMessage(EnvelopeInterface $envelope, $attempt, \Exception $exception = null) { $headers = $envelope->getHeaders(); $headers[RetryProcessor::PROPERTY_KEY] = $attempt; if ($exception) { $headers['x-exception'] = ['message' => $exception->getMessage(), 'type' => get_class($exception), 'file' => $exception->getFile(), 'line' => $exception->getLine()]; } $properties = new MessageProperties([MessageProperties::KEY_CONTENT_TYPE => $envelope->getContentType(), MessageProperties::KEY_DELIVERY_MODE => $envelope->getDeliveryMode(), MessageProperties::KEY_HEADERS => $headers, MessageProperties::KEY_PRIORITY => $envelope->getPriority()]); return new Message($envelope->getBody(), $properties, $envelope->getDeliveryTag(), $envelope->getRoutingKey()); }
/** * @inheritdoc */ public function nack(EnvelopeInterface $envelope, $requeue = false) { $this->queue->nack($envelope->getDeliveryTag(), $requeue ? QueueInterface::REQUEUE : null); }
/** * @param EnvelopeInterface $envelope * * @throws \LogicException * * @return int */ protected function getAttemptValue(EnvelopeInterface $envelope) { if (false === ($attempt = $envelope->getHeader(self::PROPERTY_KEY))) { return 1; } $attempt = (int) $attempt; if ($attempt < 1) { throw new \LogicException(sprintf('Attempt can only be a positive number, got "%s"', json_encode($attempt))); } return $attempt; }