Final Class Yiisoft\Queue\Middleware\FailureHandling\Implementation\SendAgainMiddleware
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Failure strategy which resends a message through a producer capability.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| META_KEY_RESEND | 'failure-strategy-resend-attempts' | Yiisoft\ |
Method Details
| public mixed __construct ( string $id, integer $maxAttempts, ?\ | ||
| $id | string | |
| $maxAttempts | integer | |
| $targetQueue | ?\ |
|
| $producerProvider | ?\ |
|
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.");
}
}
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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.