QueuedEnvelope example

/** * @var bool this property is used to signal if we are inside a the first/root call to * MessageBusInterface::dispatch() or if dispatch has been called inside a message handler */
    private bool $isRootDispatchCallRunning = false;

    public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        if (null !== $envelope->last(DispatchAfterCurrentBusStamp::class)) {
            if ($this->isRootDispatchCallRunning) {
                $this->queue[] = new QueuedEnvelope($envelope$stack);

                return $envelope;
            }

            $envelope = $envelope->withoutAll(DispatchAfterCurrentBusStamp::class);
        }

        if ($this->isRootDispatchCallRunning) {
            /* * A call to MessageBusInterface::dispatch() was made from inside the main bus handling, * but the message does not have the stamp. So, process it like normal. */
Home | Imprint | This part of the site doesn't use cookies.