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

example for mongodb transaction with session context #3

Open
Ja7ad opened this issue Jul 26, 2022 · 4 comments
Open

example for mongodb transaction with session context #3

Ja7ad opened this issue Jul 26, 2022 · 4 comments

Comments

@Ja7ad
Copy link

Ja7ad commented Jul 26, 2022

hi
It is my first time working with DTM for transactions in a microservice architecture.
Using mongodb in my services, I need more examples of distributed transactions.
MongoDB has transaction logic, but I do not know how to use DTM to roll back a session transaction in MongoDB.
I want add dtm to my example project: https://github.com/Ja7ad/Library
Please help me for this.

@yedf2
Copy link
Contributor

yedf2 commented Jul 26, 2022

I have take a look at your repo, and there is only a picture describing the logic.

Because MongoDB does not support XA transaction, so you should implement to rollback service manually and submit the update and rollback urls to DTM like this:

	saga := dtmcli.NewSaga(DtmServer, shortuuid.New()).
		// add a TransOut sub-transaction,forward operation with url: qsBusi+"/TransOut", reverse compensation operation with url: qsBusi+"/TransOutCom"
		Add(qsBusi+"/TransOut", qsBusi+"/TransOutCom", req).
		// add a TransIn sub-transaction, forward operation with url: qsBusi+"/TransIn", reverse compensation operation with url: qsBusi+"/TransInCom"
		Add(qsBusi+"/TransIn", qsBusi+"/TransInCom", req)
	// submit the created saga transaction,dtm ensures all sub-transactions either complete or get revoked
	err := saga.Submit()

If you want me the help, you should firstly add some docs for a new developer to run your example project easily.

@Ja7ad
Copy link
Author

Ja7ad commented Jul 26, 2022

Ok
MonogoDB having oplog on replica and logging any trigger on documents.

I will try add saga pattern for test

@Ja7ad
Copy link
Author

Ja7ad commented Jul 27, 2022

@yedf2
Copy link
Contributor

yedf2 commented Jul 27, 2022

Maybe you should finish your project without distributed transactions, and then consider how to add dtm to it.

I take a look at your project, client logics, rollback functions are not completed

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

No branches or pull requests

2 participants