Skip to content

[Messenger] Allow handler locator to be set #60753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

maxbaldanza
Copy link
Contributor

Hi,

I'd like to use the HandleMessageMiddleware but use a different locator to get the handlers of the messages. The HandleMessageMiddleware uses an interface but I can't see how to define a different implementation as the compiler pass sets this argument per bus.

I could define my own version of the handle_message middleware and provide the dependancy but this means I can no longer use the default_middleware configuration.
By checking if the locator already exists it means the application could define the HandlersLocatorInterface implementation that is used by defining something like this in their services.yaml: {$busName}.messenger.handlers_locator: '@Application\Middleware\HandlersLocator'

Would be great to hear if there's maybe a better way to do this or if I've missed a detail on how to provide the HandlersLocatorInterface

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

{
$container = $this->getContainerBuilder($busId = 'message_bus');

$container->register($busId. '.messenger.handlers_locator', \stdClass::class);
Copy link
Contributor Author

@maxbaldanza maxbaldanza Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdClass isn't the right class here but wasn't sure it was worth the effort to create a fake HandlersLocatorInterface but happy to add it if you would prefer

The `HandleMessageMiddleware` has a dependency on a `HandlersLocatorInterface`
but this gets registered by the messenger pass.

As far as I can see there isn't a way for an application to provide it's
own implementation. By checking if the service already exists before
registering then we can allow applications to define their own
@maxbaldanza maxbaldanza force-pushed the change-handlers-locator branch from fcff4ae to 8b63b8f Compare June 10, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants