Skip to content

Commit

Permalink
Use plugin-dedicated messenger command bus
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenozzi committed Sep 15, 2023
1 parent ec27184 commit f8c7b1f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
24 changes: 24 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ framework:
messenger:
routing:
'Webgriffe\SyliusAkeneoPlugin\Message\ItemImport': main

buses:
webgriffe_sylius_akeneo.command_bus:
middleware:
- 'webgriffe_sylius_akeneo.middleware.item_import_result_persister'

# each time a message is handled, the Doctrine connection
# is "pinged" and reconnected if it's closed. Useful
# if your workers run for a long time and the database
# connection is sometimes lost
- doctrine_ping_connection

# After handling, the Doctrine connection is closed,
# which can free up database connections in a worker,
# instead of keeping them open forever
- doctrine_close_connection

# wraps all handlers in a single Doctrine transaction
# handlers do not need to call flush() and an error
# in any handler will cause a rollback
- doctrine_transaction

# logs an error when a Doctrine transaction was opened but not closed
- doctrine_open_transaction_logger

monolog:
channels: ['webgriffe_sylius_akeneo_plugin']
Expand Down
4 changes: 2 additions & 2 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<service id="webgriffe_sylius_akeneo.command.import" class="Webgriffe\SyliusAkeneoPlugin\Command\ImportCommand">
<argument type="service" id="webgriffe_sylius_akeneo.date_time_builder"/>
<argument type="service" id="webgriffe_sylius_akeneo.importer_registry"/>
<argument type="service" id="messenger.default_bus"/>
<argument type="service" id="webgriffe_sylius_akeneo.command_bus"/>
<tag name="console.command" />
</service>

Expand Down Expand Up @@ -54,7 +54,7 @@
<service id="webgriffe_sylius_akeneo.controller.product_import_controller" class="Webgriffe\SyliusAkeneoPlugin\Controller\ProductImportController" >
<tag name="controller.service_arguments"/>
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="messenger.default_bus" />
<argument type="service" id="webgriffe_sylius_akeneo.command_bus" />
<argument type="service" id="translator" />
<call method="setContainer">
<argument type="service" id="service_container" />
Expand Down
21 changes: 0 additions & 21 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,3 @@ webgriffe_sylius_akeneo:
Pay attention that among these parameters there are some sensitive configuration that you probably don't want to commit
in your VCS. There are different solutions to this problem, like env configurations and secrets. Refer
to [Symfony best practices doc](https://symfony.com/doc/current/best_practices.html#configuration) for more info.
To be able to see Akeneo item import results in Sylius backend (see [Usage](usage.md) section) you should enable our dedicated Symfony Messenger middleware for the `sylius.command_bus`.
To do so you have to add the following configuration in `config/framework.yaml`:

```yaml
# ...
framework:
# ...
messenger:
# ...
sylius.command_bus:
middleware:
- 'webgriffe_sylius_akeneo.middleware.item_import_result_persister'
# The following middlewares should be copied and pasted from sylius.command_bus middlewares defined in
# vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml
- 'validation'
- 'doctrine_transaction'
```

Be aware to put the `webgriffe_sylius_akeneo.middleware.item_import_result_persister` middleware before all other middlewares defined by Sylius core (you should copy and paste them from `vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml`).
10 changes: 0 additions & 10 deletions tests/Application/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ framework:
serializer:
mapping:
paths: [ '%kernel.project_dir%/config/serialization' ]

messenger:
buses:
sylius.command_bus:
middleware:
- 'webgriffe_sylius_akeneo.middleware.item_import_result_persister'
# The following middlewares should be copied and pasted from sylius.command_bus middlewares defined in
# vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Resources/config/app/messenger.yaml
- 'validation'
- 'doctrine_transaction'

0 comments on commit f8c7b1f

Please sign in to comment.