Skip to content
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

[Messenger] Show how to configure a doctrine transaction middleware #10013

Closed
wants to merge 3 commits into from

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Jul 4, 2018

This will fix #9651

This is a first draft. Please add a quick review and after that I'll add code blocks for PHP and XML.

I use the title "Working with doctrine" because I believe we should mention the DispatchAfterCurrentBusMiddleware on this page as well. (Code PR, Doc PR) and the "recording" from entities (Code PR)

@javiereguiluz javiereguiluz changed the title [Messenger] Show ow to configure a doctrine transaction middleware [Messenger] Show how to configure a doctrine transaction middleware Jul 4, 2018
@ogizanagi
Copy link
Member

It looks great!...but we already mentioned the transaction middleware briefly in https://symfony.com/doc/current/messenger.html#using-middleware-factories where we explain middleware factories.
But having this dedicated docs really makes sense. However end-users should not have to deal with the factories themselves for this middleware as everything should be wired by the DoctrineBundle. So it could be actually simplified but doctrine/DoctrineBundle#817 isn't merged yet :'(

Users are supposed to be able to just use:

        framework:
            messenger:
                buses:
                    command_bus:
                        middleware:
                            # Using default entity manager
                            - doctrine_transaction_middleware
                            # Using "custom" entity manager
                            - doctrine_transaction_middleware: ['custom']

@Nyholm
Copy link
Member Author

Nyholm commented Jul 5, 2018

Oh, I've missed that entire page of documentation!

Okey, Lets wait for doctrine/DoctrineBundle#817

@Nyholm
Copy link
Member Author

Nyholm commented Sep 13, 2018

Now when the doctrine PR is merge, I will update these docs to the new config syntax, right?

messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
@Nyholm
Copy link
Member Author

Nyholm commented Apr 8, 2019

This PR is updated.
Ping @sroze

Copy link
Contributor

@sroze sroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me (except these two changes) 👍

messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
messenger/working-with-doctrine.rst Outdated Show resolved Hide resolved
@Nyholm
Copy link
Member Author

Nyholm commented Apr 28, 2019

Thank you for the review. I've updated the RP

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My instinct is that this should be included in the main doc, but we can figure that out later. I added one real question.

Also, correct me if I'm wrong, isn't this only relevant if you have multiple handlers that are doing flushes? So the transaction would roll back all of them (instead of some working and others not working)? I want it to be clear when a user should definitely use this versus when it won't make any difference for them.

buses:
messenger.bus.command:
middleware:
- validation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we purposely also including validation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit unrelated with the content of this doc indeed, but a good practice, as content of the command in a CQRS application are most of the input by users (on contrary of events which are mostly crafted by developers from already validated data).

@ogizanagi
Copy link
Member

@weaverryan

Also, correct me if I'm wrong, isn't this only relevant if you have multiple handlers that are doing flushes?

No it's relevant even with a single command bus and single handler for the message, so you don't have to deal with flushing changes yourself, nor you can commit changes partially to the database if a command handler failed at some point, rollbacking any change.

@OskarStark
Copy link
Contributor

Friendly ping @Nyholm 🎶 👋

Could you please find some time and finish this PR? Thank you 🙏

@javiereguiluz
Copy link
Member

I'm closing this old pull request because we already mention the doctrine_transaction in the main Messenger article (see https://symfony.com/doc/current/messenger.html#middleware-for-doctrine) so this is probably no longer needed. Thanks.

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.

[Messenger] Add a middleware that wraps all handlers in one Doctrine transaction
9 participants