@@ -9,25 +9,6 @@ writes in a single Doctrine transaction. This make sure that if one of your data
9
9
query fails, then all queries are rolled back and give you a change to handle the
10
10
exception knowing that your database was not changed by your message handler.
11
11
12
- To make sure your message bus wraps the handler in one transaction you must first
13
- register the middleware as a service.
14
-
15
- .. configuration-block ::
16
-
17
- .. code-block :: yaml
18
-
19
- # config/services.yaml
20
- services :
21
- app.messenger.middleware_factory.transaction :
22
- class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory
23
- arguments : ['@doctrine']
24
-
25
- app.doctrine_transaction_middleware :
26
- class : Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
27
- factory : ['@app.messenger.middleware_factory.transaction', 'createMiddleware']
28
- abstract : true
29
- arguments : ['default']
30
-
31
12
Next thing you need to do is to add the middleware to your bus configuration.
32
13
33
14
.. configuration-block ::
@@ -37,9 +18,47 @@ Next thing you need to do is to add the middleware to your bus configuration.
37
18
# config/packages/messenger.yaml
38
19
framework :
39
20
# ...
40
- default_bus : messenger.bus.command
41
21
buses :
42
22
messenger.bus.command :
43
23
middleware :
44
- - messenger.middleware.validation
45
- - app.doctrine_transaction_middleware : ['default']
24
+ - validation
25
+ - doctrine_transaction
26
+
27
+ .. code-block :: xml
28
+
29
+ <!-- config/packages/messenger.xml -->
30
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
31
+ <container xmlns =" http://symfony.com/schema/dic/services"
32
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
33
+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
34
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
35
+ https://symfony.com/schema/dic/services/services-1.0.xsd
36
+ http://symfony.com/schema/dic/symfony
37
+ https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
38
+
39
+ <framework : config >
40
+ <framework : messenger >
41
+ <framework : bus name =" messenger.bus.commands" >
42
+ <framework : middleware id =" validation" />
43
+ <framework : middleware id =" doctrine_transaction" />
44
+ <framework : bus >
45
+ </framework : messenger >
46
+ </framework : config >
47
+ </container >
48
+
49
+ .. code-block :: php
50
+
51
+ // config/packages/messenger.php
52
+ $container->loadFromExtension('framework', [
53
+ 'messenger' => [
54
+ 'buses' => [
55
+ 'messenger.bus.commands' => [
56
+ 'middleware' => [
57
+ 'validation',
58
+ 'doctrine_transaction',
59
+ ],
60
+ ],
61
+ ],
62
+ ],
63
+ ]);
64
+
0 commit comments