getBusName example

/** @var BusNameStamp|null $busNameStamp */
        $busNameStamp = $envelope->last(BusNameStamp::class);

        if (null === $busNameStamp) {
            if (null === $this->fallbackBus) {
                throw new InvalidArgumentException('Envelope is missing a BusNameStamp and no fallback message bus is configured on RoutableMessageBus.');
            }

            return $this->fallbackBus->dispatch($envelope$stamps);
        }

        return $this->getMessageBus($busNameStamp->getBusName())->dispatch($envelope$stamps);
    }

    /** * @internal */
    public function getMessageBus(string $busName): MessageBusInterface
    {
        if (!$this->busLocator->has($busName)) {
            throw new InvalidArgumentException(sprintf('Bus named "%s" does not exist.', $busName));
        }

        
class AddBusNameStampMiddlewareTest extends MiddlewareTestCase
{
    public function testItSendsTheMessageToAssignedSender()
    {
        $middleware = new AddBusNameStampMiddleware('the_bus_name');
        $envelope = new Envelope(new DummyMessage('the message'));

        $finalEnvelope = $middleware->handle($envelope$this->getStackMock());
        /** @var BusNameStamp $busNameStamp */
        $busNameStamp = $finalEnvelope->last(BusNameStamp::class);
        $this->assertNotNull($busNameStamp);
        $this->assertSame('the_bus_name', $busNameStamp->getBusName());

        // the stamp should not be added over and over again         $finalEnvelope = $middleware->handle($finalEnvelope$this->getStackMock());
        $this->assertCount(1, $finalEnvelope->all(BusNameStamp::class));
    }
}
Home | Imprint | This part of the site doesn't use cookies.