[Messenger] Remove DispatchAfterCurrentBusStamp when message is put on internal queue
This commit is contained in:
parent
9526988eca
commit
91f1680b3f
@ -112,7 +112,7 @@ final class QueuedEnvelope
|
|||||||
|
|
||||||
public function __construct(Envelope $envelope, StackInterface $stack)
|
public function __construct(Envelope $envelope, StackInterface $stack)
|
||||||
{
|
{
|
||||||
$this->envelope = $envelope;
|
$this->envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
|
||||||
$this->stack = $stack;
|
$this->stack = $stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,53 @@ class DispatchAfterCurrentBusMiddlewareTest extends TestCase
|
|||||||
$messageBus->dispatch($message);
|
$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
|
* @param MiddlewareInterface|MockObject $handlingMiddleware
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user