Skip to content

Commit

Permalink
Adding PHP and XML configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Apr 8, 2019
1 parent c497ed2 commit cc05ed2
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions messenger/working-with-doctrine.rst
Expand Up @@ -9,25 +9,6 @@ writes in a single Doctrine transaction. This make sure that if one of your data
query fails, then all queries are rolled back and give you a change to handle the
exception knowing that your database was not changed by your message handler.

To make sure your message bus wraps the handler in one transaction you must first
register the middleware as a service.

.. configuration-block::

.. code-block:: yaml
# config/services.yaml
services:
app.messenger.middleware_factory.transaction:
class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory
arguments: ['@doctrine']
app.doctrine_transaction_middleware:
class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
factory: ['@app.messenger.middleware_factory.transaction', 'createMiddleware']
abstract: true
arguments: ['default']
Next thing you need to do is to add the middleware to your bus configuration.

.. configuration-block::
Expand All @@ -37,9 +18,47 @@ Next thing you need to do is to add the middleware to your bus configuration.
# config/packages/messenger.yaml
framework:
# ...
default_bus: messenger.bus.command
buses:
messenger.bus.command:
middleware:
- messenger.middleware.validation
- app.doctrine_transaction_middleware: ['default']
- validation
- doctrine_transaction
.. code-block:: xml
<!-- config/packages/messenger.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:messenger>
<framework:bus name="messenger.bus.commands">
<framework:middleware id="validation"/>
<framework:middleware id="doctrine_transaction"/>
<framework:bus>
</framework:messenger>
</framework:config>
</container>
.. code-block:: php
// config/packages/messenger.php
$container->loadFromExtension('framework', [
'messenger' => [
'buses' => [
'messenger.bus.commands' => [
'middleware' => [
'validation',
'doctrine_transaction',
],
],
],
],
]);

0 comments on commit cc05ed2

Please sign in to comment.