0

Final Class Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware

InheritanceYiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware
ImplementsYiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareInterface

Failure strategy which resends a message through a producer capability.

Constants

Hide inherited constants

Constant Value Description Defined By
META_KEY_RESEND 'failure-strategy-resend-attempts' Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $id, integer $maxAttempts, ?\Yiisoft\Queue\QueueProducerInterface $targetQueue null, ?\Yiisoft\Queue\Provider\QueueProducerProviderInterface $producerProvider null )
$id string
$maxAttempts integer
$targetQueue ?\Yiisoft\Queue\QueueProducerInterface
$producerProvider ?\Yiisoft\Queue\Provider\QueueProducerProviderInterface

                public function __construct(
    private readonly string $id,
    private readonly int $maxAttempts,
    private readonly ?QueueProducerInterface $targetQueue = null,
    private readonly ?QueueProducerProviderInterface $producerProvider = null,
) {
    if ($maxAttempts < 1) {
        throw new InvalidArgumentException("maxAttempts parameter must be a positive integer, $this->maxAttempts given.");
    }
}

            
processFailure() public method

public Yiisoft\Queue\Middleware\FailureHandling\FailureHandlingRequest processFailure ( Yiisoft\Queue\Middleware\FailureHandling\FailureHandlingRequest $request, Yiisoft\Queue\Middleware\FailureHandling\FailureHandlerInterface $handler )
$request Yiisoft\Queue\Middleware\FailureHandling\FailureHandlingRequest
$handler Yiisoft\Queue\Middleware\FailureHandling\FailureHandlerInterface

                public function processFailure(FailureHandlingRequest $request, FailureHandlerInterface $handler): FailureHandlingRequest
{
    $message = $request->getMessage();
    if (!$this->suits($message)) {
        return $handler->handleFailure($request);
    }
    $envelope = new FailureEnvelope($message, [$this->getMetaKey() => $this->getAttempts($message) + 1]);
    $producer = $this->targetQueue ?? $request->getRetryProducer() ?? $this->sourceProducer($request);
    $envelope = $producer->push($envelope);
    return $request->withMessage($envelope);
}