Final Class Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware
| Inheritance | Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware |
|---|---|
| Implements | Yiisoft\Queue\Middleware\FailureHandling\MiddlewareFailureInterface |
Failure strategy which resends the given message to a queue.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| META_KEY_RESEND | 'failure-strategy-resend-attempts' | Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware |
Method Details
| public mixed __construct ( string $id, integer $maxAttempts, Yiisoft\Queue\QueueInterface|null $targetQueue = null ) | ||
| $id | string |
A unique id to differentiate two and more instances of this class |
| $maxAttempts | integer |
Maximum attempts count for this strategy with the given $id before it will give up |
| $targetQueue | Yiisoft\Queue\QueueInterface|null |
Messages will be sent to this queue if set. They will be resent to an original queue otherwise. |
public function __construct(
private readonly string $id,
private readonly int $maxAttempts,
private readonly ?QueueInterface $targetQueue = null,
) {
if ($maxAttempts < 1) {
throw new InvalidArgumentException("maxAttempts parameter must be a positive integer, $this->maxAttempts given.");
}
}
public function processFailure(
FailureHandlingRequest $request,
MessageFailureHandlerInterface $handler
): FailureHandlingRequest {
$message = $request->getMessage();
if ($this->suites($message)) {
$envelope = new FailureEnvelope($message, $this->createMeta($message));
$envelope = ($this->targetQueue ?? $request->getQueue())->push($envelope);
return $request->withMessage($envelope)
->withQueue($this->targetQueue ?? $request->getQueue());
}
return $handler->handleFailure($request);
}
Signup or Login in order to comment.