feature #64072 [Messenger] Add routing information to the `debug:messenger` command (ckrack)
This PR was merged into the 8.2 branch.
Discussion
----------
[Messenger] Add routing information to the `debug:messenger` command
| Q | A
| ------------- | ---
| Branch? | 8.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
`debug:messenger` now says where each message goes, not only which handlers it has.
Every message in the listing gains a `routed to` line, and a `Transports` section lists the routing rules once, grouped by transport, with the kind of each rule and the failure transport it feeds:
```
Transports
----------
[INFO] TransportNamesStamp can override this routing at dispatch time.
async
App\Message\OrderPlaced
App\Message\Sub\* (namespace)
App\Message\AuditableInterface (interface, matches implementers)
failed messages are routed to failed_async
failed
* (fallback for messages with no other route)
```
Routing is configured once for the whole application, not per bus, so the section is printed once, after the bus sections.
A `--message` option answers "what happens when I dispatch this class":
```bash
php bin/console debug:messenger --message='App\Message\OrderPlaced'
```
It resolves the class the way `dispatch()` does: through its parent classes, its interfaces, namespace wildcards, the `*` fallback and `#[AsMessage]` attributes, with configuration taking precedence over attributes. Handlers registered for a parent class or an interface are listed too. The output is restricted to the transports and rules that apply to that message, it works for message classes that are not registered as services, and a leading backslash in the value is accepted.
`TransportNamesStamp` overrides routing at dispatch time and no static view can see that, so the output says so rather than reading as authoritative.
To keep the command and the runtime from drifting apart, the alias half of `SendersLocator::getSenders()` moved to an internal `SendersLocator::getSenderAliases()` that both call, and `HandlersLocator` gained an internal `listTypesForClass()` taking a class name instead of an envelope. `#[AsMessage]` now records its `transport` on the `messenger.message` resource tag so the compiler pass can list attribute-routed messages in the transports view.
Points the documentation should carry:
* the two views: the whole listing, and `--message` for one class
* the rule kinds shown next to each rule, and that configuration wins over `#[AsMessage]` (including the `*` fallback, which disables attribute routing for every message)
* the failure transport line, and that a transport whose failure transport is itself does not show one
* the `TransportNamesStamp` caveat
Commits
-------
022d1f5259d [FrameworkBundle][Messenger] Add routing information to the debug:messenger command N
Nicolas Grekas committed
d4871ead7bef9da34814cbbbd04000080194b84a