Last active
November 8, 2019 12:21
-
-
Save GrzegorzBandur/8253795c11d917da0349552e6f05db2e to your computer and use it in GitHub Desktop.
Symfony Messenger: Fix problem with too many amount of Redelivery Stamps - Leave only last one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\MessageBus\Middleware; | |
use Symfony\Component\Messenger\Envelope; | |
use Symfony\Component\Messenger\Middleware\MiddlewareInterface; | |
use Symfony\Component\Messenger\Middleware\StackInterface; | |
use Symfony\Component\Messenger\Stamp\DelayStamp; | |
use Symfony\Component\Messenger\Stamp\RedeliveryStamp; | |
use Symfony\Component\Messenger\Stamp\SentStamp; | |
class OnlyLastRedeliveryStampMiddleware implements MiddlewareInterface | |
{ | |
public function handle(Envelope $envelope, StackInterface $stack): Envelope | |
{ | |
if ($envelope->last(RedeliveryStamp::class)) { | |
$lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class); | |
$lastDelayStamp = $envelope->last(DelayStamp::class); | |
$lastSentStamp = $envelope->last(SentStamp::class); | |
return $stack->next()->handle( | |
$envelope | |
->withoutAll(RedeliveryStamp::class)->with($lastRedeliveryStamp) | |
->withoutAll(DelayStamp::class)->with($lastDelayStamp) | |
->withoutAll(SentStamp::class)->with($lastSentStamp), | |
$stack | |
); | |
} | |
return $stack->next()->handle($envelope, $stack); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment