PHP code example of creatortsv / symfony-messenger-outbox-pattern

1. Go to this page and download the library: Download creatortsv/symfony-messenger-outbox-pattern library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

creatortsv / symfony-messenger-outbox-pattern example snippets


readonly class UserService
{
    public function __construct(
        private EntityManagerInterface $entityManager,
        private MessageBusInterface $eventBus,
    ) {
        // ...
    }
    
    public function register(User $user): void
    {
        $this->entityManager->wrapInTransaction(
            function () use ($user): void {
            /** Persist user in DB ... */
            
                $this->entityManager->flush();
                $this->eventBus->dispatch(new UserRegistered($user->id));
            },
        );
    }
}
shell
php bin/console messenger:consume [name]