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

Skip to content

Sender "chaining" does not work as advertised in the messenger component #27908

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

Closed
BillyMorgan opened this issue Jul 10, 2018 · 3 comments
Closed

Comments

@BillyMorgan
Copy link

Symfony version(s) affected: 4.1.1

Description
The messenger component documentation says that "A class of messages can also be routed to multiple senders by specifying a list", but this doesn't work. You get an exception stating that the SenderLocator "is a smaller service locator that only knows about the .... jobs".

How to reproduce
The documented use case ought to reproduce it:

framework:
    messenger:
        routing:
            'My\Message\ToBeSentToTwoSenders': [amqp, audit]

Possible Solution
Problem seems to be that the chained sender service that gets generated during the compiler pass is added to the global container, when it needs to be added to the service locator. Maybe?

@sroze
Copy link
Contributor

sroze commented Jul 10, 2018 via email

@BillyMorgan
Copy link
Author

Messenger config:

framework:
    messenger:
        transports:
            # Uncomment the following line to enable a transport named "amqp"
            amqp: '%env(MESSENGER_TRANSPORT_DSN)%'
            amqp2: '%env(MESSENGER_TRANSPORT_DSN)%'

        routing:
            # Route your messages to the transports
            'App\Lib\MyClass': [amqp, amqp2]

Exception:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
Service ".messenger.chain_sender.App\Lib\MyClass" not found: the container inside "Symfony\Component\Messenger\Asynchronous\Routing\SenderLocator" is a smaller service locator that only knows about the "amqp", "amqp2", "messenger.transport.amqp" and "messenger.transport.amqp2" services.

  at vendor/symfony/dependency-injection/ServiceLocator.php:51
  at Symfony\Component\DependencyInjection\ServiceLocator->get('.messenger.chain_sender.App\\Lib\\MyClass')
     (vendor/symfony/messenger/Asynchronous/Routing/SenderLocator.php:38)
  at Symfony\Component\Messenger\Asynchronous\Routing\SenderLocator->getSenderForMessage(object(MyClass))
     (vendor/symfony/messenger/Asynchronous/Middleware/SendMessageMiddleware.php:47)
  at Symfony\Component\Messenger\Asynchronous\Middleware\SendMessageMiddleware->handle(object(Envelope), object(Closure))
     (vendor/symfony/messenger/MessageBus.php:74)
  at Symfony\Component\Messenger\MessageBus->Symfony\Component\Messenger\{closure}(object(Envelope))
     (vendor/symfony/messenger/Middleware/LoggingMiddleware.php:36)
  at Symfony\Component\Messenger\Middleware\LoggingMiddleware->handle(object(MyClass), object(Closure))
     (vendor/symfony/messenger/MessageBus.php:74)
  at Symfony\Component\Messenger\MessageBus->Symfony\Component\Messenger\{closure}(object(MyClass))
     (vendor/symfony/messenger/MessageBus.php:47)
  at Symfony\Component\Messenger\MessageBus->dispatch(object(MyClass))
     (vendor/symfony/messenger/TraceableMessageBus.php:37)
  at Symfony\Component\Messenger\TraceableMessageBus->dispatch(object(MyClass))
     (src/Controller/MyController.php:21)
  at App\Controller\MyController->MyAction(object(TraceableMessageBus))
     (vendor/symfony/http-kernel/HttpKernel.php:149)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:66)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:188)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:37)

@sroze
Copy link
Contributor

sroze commented Jul 20, 2018

Good catch. The following PR should fix it: #28014.

sroze added a commit that referenced this issue Jul 25, 2018
This PR was merged into the 4.1 branch.

Discussion
----------

[Messenger] Fix chaining senders with their aliases

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27908
| License       | MIT
| Doc PR        | ø

Turns out chaining senders when using their alias as the name is broken. This PR fixes it :)

Commits
-------

98bb64c Chaining senders with their aliases should work
@sroze sroze closed this as completed Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants