Skip to content

Commit

Permalink
NGSTACK-805: load default Messenger configuration automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Nov 15, 2023
1 parent 2181f9f commit 34e4678
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 63 deletions.
19 changes: 18 additions & 1 deletion bundle/DependencyInjection/NetgenIbexaSearchExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
*/
Expand Down
105 changes: 51 additions & 54 deletions bundle/Resources/config/messenger.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 4 additions & 7 deletions docs/reference/asynchronous_indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/netgen/ibexa-search-extra/blob/master/bundle/Resources/config/messenger.yaml>`_
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 <https://github.com/netgen/ibexa-search-extra/blob/master/bundle/Resources/config/messenger.yaml>`_
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
Expand Down

0 comments on commit 34e4678

Please sign in to comment.