Get support for goetas/messenger-doctrine-outbox

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

goetas/messenger-doctrine-outbox

goetas/messenger-doctrine-outbox

This library provides a middleware and a transport to implement the Transactional outbox pattern for the symfony/messenger component.

Installation

The recommended installation is via Composer.

composer require goetas/messenger-doctrine-outbox:@dev

Configuration

# config/packages/messenger.yaml
framework:
    messenger:
        transports:

            # add to the list of transport the outbox transport
            outbox:
                dsn: 'outbox-doctrine://default' # "default" in this case is the name of your default doctrine connection
                options:
                    queue_name: outbox # the queue name is mandatory to avoid conflicts with doctrine transport


        buses:
            event.bus:
                middleware:
                    # add to your middlewares the outbox middleware service
                    - 'app.messenger_doctrine_outbox_middleware'

# config/services.yaml
services:
    # define your outbox middleware service
    app.messenger_doctrine_outbox_middleware:
        class: Goetas\MessengerDoctrineOutbox\OutboxMiddleware
        arguments:
            - '@messenger.transport.outbox'

    # define the outbox transport factory
    goetas.messenger_doctrine_outbox_middleware:
        class: Goetas\MessengerDoctrineOutbox\OutboxTransportFactory
        arguments:
            - '@doctrine'
        tags:
            - { name: messenger.transport_factory }

Usage

// src/Controller/DefaultController.php
namespace App\Controller;

use App\Message\SmsNotification;
use App\Entity\Sms;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Messenger\MessageBusInterface;

class DefaultController extends AbstractController
{
    public function sendSms(MessageBusInterface $bus, EntityManagerInterface $em)
    {
        $sms = new Sms('hello', '123');

        $em->wrapInTransaction(function() {
            $em->persist($sms);
            $bus->dispatch(new SmsNotification('Look! I created a message!'));
        });
    }

    // if you do not want to use wrapInTransaction()...
    public function sendDifferentSms(MessageBusInterface $bus, EntityManagerInterface $em)
    {
        $sms = new Sms('hello', '123');

        try {
            $em->beginTransaction();

            $em->persist($sms);
            $em->flush();
            $bus->dispatch(new SmsNotification('Look! I created a message!'));

            $em->commit();
        } catch (\Throwable $exception) {
            $em->rollback();
        }
    }
}

Running the outbox consumer

You can run only the outbox consumer with this command:

bin/consone bin/console  messenger:consume outbox

You can also run all the consumers with the following command.

bin/consone bin/console  messenger:consume
Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2