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

Add docs on publishing messages in transactions with help of Forwarder component #261

Merged
merged 17 commits into from
Mar 17, 2022

Conversation

czeslavo
Copy link
Contributor

No description provided.

@danielllek
Copy link

Probably not a docs problem, but when using example as stupid copy&paste on postgresql it produces error:
cannot publish messages to forwarder topic: 'events-to-forward': cannot initialize schema: cound not initialize schema: pq: syntax error at or near \"-\"

Probably escaping problem as you can create table with dashes on postgres when properly escaped :)

+++

## Publishing messages in transactions (and why we should care)
While working with an event-driven application, you may in some point need to store an application state and publish a message
Copy link
Member

Choose a reason for hiding this comment

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

It may be good to add tl;dr a problem statement in the first paragraph. Just to ensure that reader will instantly know what is the problem. If he will not find it in the first paragraph, it's a high chance that he will not read it further. Later we can go into the details and example 😉

It may be worth mentioning that we are avoiding two phrase commit + some diagram. (bonus point for diagram in .svg).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the first paragraph focused on a problem and its solution - the Forwarder. :P svg diagram explaining how the component works added as well.

mechanism which happens to be implemented by most of the databases in today's world. One of them is MySQL used in our
example.

In order to commit both storing data and emitting an event in one transaction, we'd have to be able to publish our
Copy link
Member

Choose a reason for hiding this comment

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

IMO it would be good to put this and the next paragraph on the top: just to let know the reader what this component gives to him. If it will be here, it's a big chance that he will not read it 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above.

While working with an event-driven application, you may in some point need to store an application state and publish a message
telling the rest of the system about what just happened. As it may look trivial at a first glance, it could become
a bit tricky if we consider what can go wrong in case we won't pay enough attention to details.

Copy link
Member

Choose a reason for hiding this comment

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

it would be cool to link here to watermill.io component docs 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Linked to the component source code.


This example presents a solution to this problem: saving events in transaction along with persisting application state.
It also compares two other approaches which lack transactional publishing therefore expose application to a risk
of inconsistency across the system.
Copy link
Member

Choose a reason for hiding this comment

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

Some diagram may be nice here 😉 miro works pretty well for diagrams, draw.io as well. It could be added in watermill.io as well 😉

@czeslavo
Copy link
Contributor Author

Probably not a docs problem, but when using example as stupid copy&paste on postgresql it produces error: cannot publish messages to forwarder topic: 'events-to-forward': cannot initialize schema: cound not initialize schema: pq: syntax error at or near \"-\"

Probably escaping problem as you can create table with dashes on postgres when properly escaped :)

Thanks for info. I've changed the topic name to not include dashes to make it simpler. :)

@roblaszczak roblaszczak merged commit 22287d3 into ThreeDotsLabs:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants