0

As explained in the documentation of the Symfony messenger component, by default message handlers handle messages from all message buses. However, one can restrict a message handler to a specific bus like this:

# config/services.yaml
services:
    App\MessageHandler\SomeCommandHandler:
        tags: [{ name: messenger.message_handler, bus: command.bus }]
        # prevent handlers from being registered twice (or you can remove
        # the MessageHandlerInterface that autoconfigure uses to find handlers)
        autoconfigure: false

Now for a project I am working on, I have three buses, and I would like a handler to only handle messages on two of those buses.

Is anybody aware of a way to achieve this?

johanv
  • 962
  • 8
  • 11

1 Answers1

1

It's just a wild guess, but as tags is an array, could you try to add multiple tags?

# config/services.yaml
services:
    App\MessageHandler\SomeCommandHandler:
        tags: 
            - { name: messenger.message_handler, bus: command.bus }
            - { name: messenger.message_handler, bus: command.bus_2 }
virtualize
  • 2,287
  • 2
  • 25
  • 36
  • This works, thank you! I was a little confused because there were two tags with the same name, but that doesn't seem to be a problem. – johanv Jan 16 '20 at 06:35