B
B
BonBon Slick2020-12-07 15:39:58
symfony
BonBon Slick, 2020-12-07 15:39:58

Serial message bus command?

Transactional Messages: Handle New Messages After ...

class RegisterUserHandler
{
    private $eventBus;
    private $em;

    public function __construct(MessageBusInterface $eventBus, EntityManagerInterface $em)
    {
        $this->eventBus = $eventBus;
        $this->em = $em;
    }

    public function __invoke(RegisterUser $command)
    {
        $user = new User($command->getUuid(), $command->getName(), $command->getEmail());
        $this->em->persist($user);

        // The DispatchAfterCurrentBusStamp marks the event message to be handled
        // only if this handler does not throw an exception.

        $event = new UserRegistered($command->getUuid());
        $this->eventBus->dispatch(
            (new Envelope($event))
                ->with(new DispatchAfterCurrentBusStamp())
        );

        // ...
    }
}


Or enough
$this->eventBus->dispatch(ew UserRegistered($command->getUuid())  );

After all, if the exception, then the dispatcher will not be called because the execution of the code will be stopped.
And then what's the point of sculpting Envole and so on?

What's the difference if you put a regular dispatcher after all the code?
Which approach to use and why?
How does this affect the transport if it is connected?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question