bug #32027 [Messenger] Remove DispatchAfterCurrentBusStamp when message is put on internal queue (Nyholm)
This PR was merged into the 4.3 branch.
Discussion
----------
[Messenger] Remove DispatchAfterCurrentBusStamp when message is put on internal queue
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #32009
| License | MIT
| Doc PR |
This will fix #32009.
Thank you @brpauwels for the report.
I consider it safe to remove the `DispatchAfterCurrentBusStamp` because its meaning disappear after we handled the "current bus".
T0: We add the stamp
T1: We put the envelope on an internal queue in `DispatchAfterCurrentBusMiddleware`
T2: We handle the current bus.
T3: We start processing our internal queue.
At T3 there we are "after current bus", that is why we dont need the stamp any more.
Commits
-------
91f1680b3f
[Messenger] Remove DispatchAfterCurrentBusStamp when message is put on internal queue
This commit is contained in:
commit
7822b3cbc0
|
@ -112,7 +112,7 @@ final class QueuedEnvelope
|
|||
|
||||
public function __construct(Envelope $envelope, StackInterface $stack)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
$this->envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
|
||||
$this->stack = $stack;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,53 @@ class DispatchAfterCurrentBusMiddlewareTest extends TestCase
|
|||
$messageBus->dispatch($message);
|
||||
}
|
||||
|
||||
public function testHandleDelayedEventFromQueue()
|
||||
{
|
||||
$message = new DummyMessage('Hello');
|
||||
$event = new DummyEvent('Event on queue');
|
||||
|
||||
$middleware = new DispatchAfterCurrentBusMiddleware();
|
||||
$commandHandlingMiddleware = $this->createMock(MiddlewareInterface::class);
|
||||
$eventHandlingMiddleware = $this->createMock(MiddlewareInterface::class);
|
||||
|
||||
// This bus simulates the bus that are used when messages come back form the queue
|
||||
$messageBusAfterQueue = new MessageBus([
|
||||
// Create a new middleware
|
||||
new DispatchAfterCurrentBusMiddleware(),
|
||||
$eventHandlingMiddleware,
|
||||
]);
|
||||
|
||||
$fakePutMessageOnQueue = $this->createMock(MiddlewareInterface::class);
|
||||
$fakePutMessageOnQueue->expects($this->any())
|
||||
->method('handle')
|
||||
->with($this->callback(function ($envelope) use ($messageBusAfterQueue) {
|
||||
// Fake putting the message on the queue
|
||||
// Fake reading the queue
|
||||
// Now, we add the message back to a new bus.
|
||||
$messageBusAfterQueue->dispatch($envelope);
|
||||
|
||||
return true;
|
||||
}))
|
||||
->willReturnArgument(0);
|
||||
|
||||
$eventBus = new MessageBus([
|
||||
$middleware,
|
||||
$fakePutMessageOnQueue,
|
||||
]);
|
||||
|
||||
$messageBus = new MessageBus([
|
||||
$middleware,
|
||||
new DispatchingMiddleware($eventBus, [
|
||||
new Envelope($event, [new DispatchAfterCurrentBusStamp()]),
|
||||
]),
|
||||
$commandHandlingMiddleware,
|
||||
]);
|
||||
|
||||
$this->expectHandledMessage($commandHandlingMiddleware, 0, $message);
|
||||
$this->expectHandledMessage($eventHandlingMiddleware, 0, $event);
|
||||
$messageBus->dispatch($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MiddlewareInterface|MockObject $handlingMiddleware
|
||||
*/
|
||||
|
|
Reference in New Issue