Skip to content

Commit 7822b3c

Browse files
committed
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 ------- 91f1680 [Messenger] Remove DispatchAfterCurrentBusStamp when message is put on internal queue
2 parents 3634390 + 91f1680 commit 7822b3c

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/Symfony/Component/Messenger/Middleware/DispatchAfterCurrentBusMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final class QueuedEnvelope
112112

113113
public function __construct(Envelope $envelope, StackInterface $stack)
114114
{
115-
$this->envelope = $envelope;
115+
$this->envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
116116
$this->stack = $stack;
117117
}
118118

src/Symfony/Component/Messenger/Tests/Middleware/DispatchAfterCurrentBusMiddlewareTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,53 @@ public function testThrowingEventsHandlingWontStopExecution()
9999
$messageBus->dispatch($message);
100100
}
101101

102+
public function testHandleDelayedEventFromQueue()
103+
{
104+
$message = new DummyMessage('Hello');
105+
$event = new DummyEvent('Event on queue');
106+
107+
$middleware = new DispatchAfterCurrentBusMiddleware();
108+
$commandHandlingMiddleware = $this->createMock(MiddlewareInterface::class);
109+
$eventHandlingMiddleware = $this->createMock(MiddlewareInterface::class);
110+
111+
// This bus simulates the bus that are used when messages come back form the queue
112+
$messageBusAfterQueue = new MessageBus([
113+
// Create a new middleware
114+
new DispatchAfterCurrentBusMiddleware(),
115+
$eventHandlingMiddleware,
116+
]);
117+
118+
$fakePutMessageOnQueue = $this->createMock(MiddlewareInterface::class);
119+
$fakePutMessageOnQueue->expects($this->any())
120+
->method('handle')
121+
->with($this->callback(function ($envelope) use ($messageBusAfterQueue) {
122+
// Fake putting the message on the queue
123+
// Fake reading the queue
124+
// Now, we add the message back to a new bus.
125+
$messageBusAfterQueue->dispatch($envelope);
126+
127+
return true;
128+
}))
129+
->willReturnArgument(0);
130+
131+
$eventBus = new MessageBus([
132+
$middleware,
133+
$fakePutMessageOnQueue,
134+
]);
135+
136+
$messageBus = new MessageBus([
137+
$middleware,
138+
new DispatchingMiddleware($eventBus, [
139+
new Envelope($event, [new DispatchAfterCurrentBusStamp()]),
140+
]),
141+
$commandHandlingMiddleware,
142+
]);
143+
144+
$this->expectHandledMessage($commandHandlingMiddleware, 0, $message);
145+
$this->expectHandledMessage($eventHandlingMiddleware, 0, $event);
146+
$messageBus->dispatch($message);
147+
}
148+
102149
/**
103150
* @param MiddlewareInterface|MockObject $handlingMiddleware
104151
*/

0 commit comments

Comments
 (0)