Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle][Messenger] Add support for namespace wildcard in Messenger routing #48531

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

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

brzuchal
Copy link
Contributor

@brzuchal brzuchal commented Dec 7, 2022

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
License MIT
Doc PR symfony/symfony-docs#17532

This is a new feature for the Messenger component which is why there is no issue ticket attached.

Currently, HandlersLocator extracts message class along with all parent classes and all interfaces + a '*' wildcard to match any transport.
This is not fully efficient resulting in many routes for messages that share the same transport but by design don't share any inheritance or interface.

This is an opportunity to introduce simple wildcards which allow defining a transport for multiple messages grouped in one namespace.
For eg. given a bunch of messages acting as commands, queries, and events (in CQRS)

  • App\Message\Command\CreatePost
  • App\Message\Command\PublishPost
  • App\Message\Event\PostCreated
  • App\Message\Event\PostPublished
  • App\Message\Query\FindPost

The intention may be to send all Commands to async transport, Queries to sync transport but Events to a different transport for eg. stream - the configuration requires creating routing for at least 3 classes because none of them share inheritance or interfaces with one wildcard '*' for async or sync as these are the most numerous.

framework:
    messenger:
        routing:
            App\Message\Command\CreatePost: async
            App\Message\Command\PublishPost: async
            App\Message\Query\FindPost: sync
            '*': stream

With this feature managing, multiple types of transport allow us to ultimately define 3 wildcarded namespaces instead and reduce the maintenance burden at the same time and prevent using standalone '*' which unconsciously may be the cause of problems. The configuration using namespace wildcards will look as follows:

framework:
    messenger:
        routing:
            App\Message\Command\*: async
            App\Message\Event\*: stream
            App\Message\Query\*: sync
#            '*': stream

The aim of this PR is to provide a simple solution supporting wildcards in routing to prevent using '*'. In future scope, matching rules may be the subject of another PR addressing improvements in the future.

@carsonbot carsonbot added this to the 6.3 milestone Dec 7, 2022
@carsonbot carsonbot changed the title [Messenger] [FrameworkBundle] Add support for namespace wildcard in Messenger routing [FrameworkBundle][Messenger] Add support for namespace wildcard in Messenger routing Dec 7, 2022
@ghost
Copy link

ghost commented Dec 7, 2022

You could also introduce marker interface like interface Command {} in your application.

@brzuchal
Copy link
Contributor Author

brzuchal commented Dec 8, 2022

@javaDeveloperKid thanks but this feature as stated in description is about avoiding marker interfaces and any inheritance. Introducing a marker interfaces would be additional coupling and changing the code to adjust infrastructure related setup. At this point I believe it's better and cleaner to define wildcard namespace in routing. Considering the fact that such configuration have influence only on senders it is purely infrastructure thing.

@brzuchal brzuchal force-pushed the wildcard-messenger-routing branch from c08f18f to cbd2f81 Compare December 12, 2022 09:38
@brzuchal
Copy link
Contributor Author

brzuchal commented Dec 12, 2022

Sorry it looks like I don't know how to use git rebase properly

@nicolas-grekas nicolas-grekas force-pushed the wildcard-messenger-routing branch from cbd2f81 to b93b443 Compare December 15, 2022 14:08
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I rebased + squashed + made some minor changes.
LGTM thanks!

@nicolas-grekas nicolas-grekas force-pushed the wildcard-messenger-routing branch from b93b443 to c352f53 Compare December 21, 2022 21:30
@nicolas-grekas
Copy link
Member

Thank you @brzuchal.

@nicolas-grekas nicolas-grekas merged commit a826eb3 into symfony:6.3 Dec 21, 2022
@brzuchal brzuchal deleted the wildcard-messenger-routing branch December 22, 2022 03:55
@fabpot fabpot mentioned this pull request May 1, 2023
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.

3 participants