/** * @param TransportReceiveContext $context * @param callable $next * * @throws \Exception */ public function invoke($context, callable $next) { try { $next(); } catch (CriticalErrorException $e) { // no retry for critical errors throw $e; } catch (MessageDeserializationException $e) { // no retry for invalid messages throw $e; } catch (\Exception $e) { $messageId = $context->getMessageId(); $numberOfRetries = $this->retryStorage->getFailuresForMessage($messageId); if ($this->retryPolicy->shouldGiveUp($numberOfRetries)) { $this->retryStorage->clearFailuresForMessage($messageId); $message = $context->getMessage(); $message->setHeader(FirstLevelRetryHeaderTypeEnum::RETRIES, $numberOfRetries); throw $e; } $this->retryStorage->incrementFailuresForMessage($context->getMessageId()); $context->abortReceiveOperation(); } }
/** * @param TransportReceiveContext $context * @param callable $next * * @throws \Exception */ public function invoke($context, callable $next) { $messageId = $context->getMessageId(); $physicalMessageContext = $this->incomingContextFactory->createPhysicalMessageContext($context); $deduplicationEntry = $this->outboxStorage->get($messageId); $pendingTransportOperations = $physicalMessageContext->getPendingTransportOperations(); if (!$deduplicationEntry) { $this->outboxStorage->beginTransaction(); try { $next($physicalMessageContext); $outboxOperations = $this->operationsConverter->convertToOutboxOperations($pendingTransportOperations); $outboxMessage = new OutboxMessage($messageId, $outboxOperations); $this->outboxStorage->store($outboxMessage); $this->outboxStorage->commit(); } catch (\Exception $e) { $this->outboxStorage->rollBack(); throw $e; } } else { $pendingTransportOperations = $this->operationsConverter->convertToPendingTransportOperations($deduplicationEntry); } $this->dispatchPendingOperations($pendingTransportOperations, $physicalMessageContext); $this->outboxStorage->markAsDispatched($messageId); }