From 34e46789a3a57716ff3780ff14cca6c65188b338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0panja?= Date: Wed, 15 Nov 2023 10:41:50 +0100 Subject: [PATCH] NGSTACK-805: load default Messenger configuration automatically --- .../NetgenIbexaSearchExtraExtension.php | 19 +++- bundle/Resources/config/messenger.yaml | 105 +++++++++--------- composer.json | 2 +- docs/reference/asynchronous_indexing.rst | 11 +- 4 files changed, 74 insertions(+), 63 deletions(-) diff --git a/bundle/DependencyInjection/NetgenIbexaSearchExtraExtension.php b/bundle/DependencyInjection/NetgenIbexaSearchExtraExtension.php index f99e43a1..729acae5 100644 --- a/bundle/DependencyInjection/NetgenIbexaSearchExtraExtension.php +++ b/bundle/DependencyInjection/NetgenIbexaSearchExtraExtension.php @@ -5,13 +5,16 @@ namespace Netgen\Bundle\IbexaSearchExtraBundle\DependencyInjection; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\Yaml\Yaml; use function array_key_exists; -class NetgenIbexaSearchExtraExtension extends Extension +class NetgenIbexaSearchExtraExtension extends Extension implements PrependExtensionInterface { public function getAlias(): string { @@ -49,6 +52,20 @@ public function load(array $configs, ContainerBuilder $container): void $this->processExtensionConfiguration($configs, $container); } + public function prepend(ContainerBuilder $container): void + { + $configs = [ + 'messenger.yaml' => 'framework', + ]; + + foreach ($configs as $fileName => $extensionName) { + $configFile = __DIR__ . '/../Resources/config/' . $fileName; + $config = Yaml::parse((string) file_get_contents($configFile)); + $container->prependExtensionConfig($extensionName, $config); + $container->addResource(new FileResource($configFile)); + } + } + /** * @throws \Exception */ diff --git a/bundle/Resources/config/messenger.yaml b/bundle/Resources/config/messenger.yaml index 0d17af45..7295a1f3 100644 --- a/bundle/Resources/config/messenger.yaml +++ b/bundle/Resources/config/messenger.yaml @@ -1,54 +1,51 @@ -# This is an example Symfony Messenger component configuration for asynchronous indexing. -# Use it if it fits your needs, or create your own as you require. -framework: - messenger: - reset_on_message: true - transports: - netgen_ibexa_search_extra_asynchronous_indexing: - dsn: '%env(MESSENGER_TRANSPORT_DSN)%' - failure_transport: netgen_ibexa_search_extra_asynchronous_indexing_failed - retry_strategy: - max_retries: 5 - delay: 1000 - multiplier: 3 - max_delay: 600000 - options: - redeliver_timeout: 300 - queue_name: netgen_ibexa_search_extra_asynchronous_indexing - netgen_ibexa_search_extra_asynchronous_indexing_failed: "doctrine://default?queue_name=netgen_ibexa_search_extra_asynchronous_indexing_failed" - routing: - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\CopyContent': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteContent': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteTranslation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\HideContent': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\PublishVersion': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\RevealContent': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\UpdateContentMetadata': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\AssignSectionToSubtree': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\CopySubtree': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\CreateLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\DeleteLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\HideLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\MoveSubtree': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\SwapLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\UnhideLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\UpdateLocation': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\ObjectState\SetContentState': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Section\AssignSection': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Trash\Recover': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Trash\Trash': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\AssignUserToUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\BeforeUnAssignUserFromUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\CreateUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\CreateUser': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\DeleteUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\DeleteUser': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\MoveUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UnAssignUserFromUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UpdateUserGroup': netgen_ibexa_search_extra_asynchronous_indexing - 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UpdateUser': netgen_ibexa_search_extra_asynchronous_indexing - default_bus: messenger.bus.default - buses: - messenger.bus.default: - middleware: - - doctrine_ping_connection +messenger: + reset_on_message: true + transports: + netgen_ibexa_search_extra_asynchronous_indexing: + dsn: '%env(MESSENGER_TRANSPORT_DSN)%' + failure_transport: netgen_ibexa_search_extra_asynchronous_indexing_failed + retry_strategy: + max_retries: 5 + delay: 1000 + multiplier: 3 + max_delay: 600000 + options: + redeliver_timeout: 300 + queue_name: netgen_ibexa_search_extra_asynchronous_indexing + netgen_ibexa_search_extra_asynchronous_indexing_failed: "doctrine://default?queue_name=netgen_ibexa_search_extra_asynchronous_indexing_failed" + routing: + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\CopyContent': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteContent': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\DeleteTranslation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\HideContent': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\PublishVersion': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\RevealContent': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\UpdateContentMetadata': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\AssignSectionToSubtree': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\CopySubtree': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\CreateLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\DeleteLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\HideLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\MoveSubtree': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\SwapLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\UnhideLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Location\UpdateLocation': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\ObjectState\SetContentState': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Section\AssignSection': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Trash\Recover': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Trash\Trash': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\AssignUserToUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\BeforeUnAssignUserFromUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\CreateUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\CreateUser': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\DeleteUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\DeleteUser': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\MoveUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UnAssignUserFromUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UpdateUserGroup': netgen_ibexa_search_extra_asynchronous_indexing + 'Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UpdateUser': netgen_ibexa_search_extra_asynchronous_indexing + default_bus: messenger.bus.default + buses: + messenger.bus.default: + middleware: + - doctrine_ping_connection diff --git a/composer.json b/composer.json index 1cf158ba..5f6c60b1 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "ext-json": "*", "ext-dom": "*", "ibexa/core": "^4.5", + "symfony/messenger": "^5.4", "symfony/proxy-manager-bridge": "^5.4" }, "require-dev": { "ibexa/fieldtype-richtext": "^4.5", "ibexa/solr": "^4.5", - "symfony/messenger": "^5.4", "phpunit/phpunit": "^8.5", "matthiasnoback/symfony-dependency-injection-test": "^4.1", "behat/behat": "^3.6.1", diff --git a/docs/reference/asynchronous_indexing.rst b/docs/reference/asynchronous_indexing.rst index 73e1f309..83f03053 100644 --- a/docs/reference/asynchronous_indexing.rst +++ b/docs/reference/asynchronous_indexing.rst @@ -17,13 +17,10 @@ In order to enable asynchronous indexing, use the following configuration: netgen_ibexa_search_extra: use_asynchronous_indexing: true -Together with the configuration above, you will need to configure the Messenger component so that messages are handled -through the queue. Otherwise, the Messenger's mechanism will handle them them synchronously. An -`example configuration `_ -for that is provided. If it fits your use case, use it, otherwise be free to implement your own. - -Additionally, you will need to start the consumer to process the queue. For the example configuration, you would do that -with: +`Default Messenger component configuration `_ +will be automatically loaded. In case you want to use a different configuration, you will have to override it in the +project code. Additionally, you will need to start the consumer to process the queue. For the default configuration, +you can do that with: .. code-block:: console