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

Skip to content

[FrameworkBundle][Messenger] Extend note on routing with support for wildcard routes #17532

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
Jun 15, 2023

Conversation

brzuchal
Copy link
Contributor

@brzuchal brzuchal commented Dec 7, 2022

Extend wildcard '*' note with information about the usage of namespace wildcards.

@carsonbot carsonbot added this to the 6.3 milestone Dec 7, 2022
@carsonbot carsonbot changed the title [Messenger] [FrameworkBundle] Extend note on routing with support for wildcard routes [FrameworkBundle][Messenger] Extend note on routing with support for wildcard routes Dec 7, 2022
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Dec 21, 2022
… wildcard in Messenger routing (brzuchal)

This PR was merged into the 6.3 branch.

Discussion
----------

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

| 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.

```yaml
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:

```yaml
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.

Commits
-------

c352f53 [FrameworkBundle][Messenger] Add support for namespace wildcard in Messenger routing
@javiereguiluz javiereguiluz changed the base branch from 6.3 to 6.2 June 15, 2023 10:58
@javiereguiluz javiereguiluz force-pushed the wildcard-messenger-routing branch from 6e4ab82 to c4e2655 Compare June 15, 2023 10:59
@javiereguiluz javiereguiluz merged commit c142399 into symfony:6.2 Jun 15, 2023
@javiereguiluz
Copy link
Member

Thanks Michał!

@brzuchal brzuchal deleted the wildcard-messenger-routing branch June 15, 2023 11: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.

4 participants