thephpleague / tactician-bundle

Bundle to integrate Tactician with Symfony projects
MIT License
245 stars 43 forks source link

Configure two command buses #105

Closed carnau closed 6 years ago

carnau commented 6 years ago

I've been following the README but I can get this working. I want to have two command buses that doesn't share the same commands, but seems that adding the bus tag in services.yml is not enough.

Do I have to add any other configuration? Adding the default handler as console works, but I guess that then it will not find the commands of the default bus.

tactician:
    commandbus:
        default:
            middleware:
                - tactician.middleware.custom_middleware
                - tactician.middleware.another_custom_middleware
                - tactician.middleware.command_handler
        console:
            middleware:
                - tactician.middleware.command_handler
App\Application\Handler\ExampleHandler:
        class: App\Application\Handler\ExampleHandler
        autowire: false
        arguments:
            - '@App\Infrastructure\Http\Example\Client'
        tags:
            - { name: tactician.handler, command: App\Application\Command\ExampleCommand, bus: console }

Missing handler for command App\Application\Command\ExampleCommand

tyx commented 6 years ago

Hello ! It should definitively work with your config.

Please can you check you use the correct bus ? It should be tactician.commandbus.console according to your config.

carnau commented 6 years ago

Hello, I've checked it and seems fine to me.

App\Infrastructure\Ui\Console\Command\ExampleCommand:
        class: App\Infrastructure\Ui\Console\Command\ExampleCommand
        arguments:
            - '@tactician.commandbus.console'
tyx commented 6 years ago

Ok, did you try to run bin/console debug:tactician ? Can you share the output and the bundle version you use ?

carnau commented 6 years ago

The command shows all the commands in both buses by default. I've added the tag bus to my command; now was removed from the default and it's only available in the console one.

Can't post output but I'll do a PoC as soon as I have free time.

Versions:

league/tactician                    v1.0.3     A small, flexible command bu...
league/tactician-bundle             v1.1.5     Bundle to integrate Tacticia...
league/tactician-container          2.0.0      Tactician integration for an...
league/tactician-doctrine           v1.1.1     Plugins for Tactician comman...
league/tactician-logger             v0.10.0    Adds PSR-3 logging support t...
rosstuck commented 6 years ago

Hey @carnau, sorry to hear you're having trouble using this, my apologies :)

I haven't used the bundle for a bit lately, but I think your issue is passing the "default" command_handler middleware to the console bus.

If you take a peek at this part of the README carefully (and I think we need a README PR to make this clearer), we autocreate a custom command_handler middleware for each bus: https://github.com/thephpleague/tactician-bundle#configuring-multiple-command-buses. In that example, the last middleware for the "accounting bus" is different than the last middleware for the default bus above it.

If I look at your example config above, both command buses are getting tactician.middleware.command_handler as their final middleware. That one contains the list of commands that are allowed only for the default bus, NOT for the console bus. So, the final middleware should be tactician.commandbus.console.middleware.command_handler

I'm fairly certain that's the issue, especially since tactician:debug is showing the expected setup.

If that doesn't fix it, I'm a bit stumped and would love to get more details or to double check if the sanitized examples you've posted are still the same as the actual app. :crossed_fingers:

carnau commented 6 years ago

@rosstuck Many thanks for your time, I've just checked it and works as expected with your suggestion. Making it clearer in the docs sounds good πŸ‘

@tyx Thanks for your help too

rosstuck commented 6 years ago

Awesome, glad to hear it! If you've got any suggestions on what we could say in the docs to clarify, or would like to send a PR, would love to merge it! :)

On Fri, Oct 12, 2018, 6:30 PM Carlos Arnau Ros notifications@github.com wrote:

@rosstuck https://github.com/rosstuck Many thanks for your time, I've just checked it and works as expected with your suggestion. Making it clearer in the docs sounds good πŸ‘

@tyx https://github.com/tyx Thanks for your help too

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/thephpleague/tactician-bundle/issues/105#issuecomment-429384287, or mute the thread https://github.com/notifications/unsubscribe-auth/AAI9Tixt2hfgM18seP7bagzhQT5wW2S4ks5ukMOYgaJpZM4XV7Bv .

carnau commented 6 years ago

Sure, I have a few days off but will send a PR sometime this week.

carnau commented 6 years ago

Added PR #106 . Closing as there's nothing left here.