Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The new client for dtm in csharp, including workflow, dtmcli, and dtmgrpc

License

NotificationsYou must be signed in to change notification settings

dtm-labs/client-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English |简体中文

dtmcli-csharp

dtmcli-csharp is the C# client of Distributed Transaction ManagerDTM that communicates with DTM Server through HTTP protocol.

It has supported distributed transaction patterns of Saga pattern, TCC pattern and 2-phase message pattern.

Build_And_Testcodecov

What is DTM

DTM is a distributed transaction solution which provides cross-service eventually data consistency. It provides saga, tcc, xa, 2-phase message strategies for a variety of application scenarios. It also supports multiple languages and multiple store engine to form up a transaction as following:

function-picture

Features

  • Extremely easy to adapt

    • Support HTTP and gRPC, provide easy-to-use programming interfaces, lower substantially the barrier of getting started with distributed transactions. Newcomers can adapt quickly.
  • Easy to use

    • Relieving developers from worrying about suspension, null compensation, idempotent transaction, and other tricky problems, the framework layer handles them all.
  • Language-agnostic

    • Suit for companies with multiple-language stacks.Easy to write bindings for Go, Python, PHP, Node.js, Ruby, and other languages.
  • Easy to deploy, easy to extend

    • DTM depends only on MySQL, easy to deploy, cluster, and scale horizontally.
  • Support for multiple distributed transaction protocol

    • TCC, SAGA, XA, Transactional messages.

DTM vs. others

There is no mature open-source distributed transaction framework for non-Java languages.Mature open-source distributed transaction frameworks for Java language include Ali's Seata, Huawei's ServiceComb-Pack, Jingdong's shardingsphere, himly, tcc-transaction, ByteTCC, and so on, of which Seata is most widely used.

The following is a comparison of the main features of dtm and Seata.

FeaturesDTMSeataRemarks
Supported languagesGolang, C#, Java, Python, PHP, and othersJavadtm allows easy access from a new language
Exception handlingSub-transaction barriermanualdtm solves idempotent transaction, hanging, null compensation
TCC
XA
ATsuggest XAAT is similar to XA with better performance but with dirty rollback
SAGAsupport concurrencycomplicated state-machine modedtm's state-machine mode is being planned
Transactional Messagingdtm provides Transactional Messaging similar to RocketMQ
Multiple DBs in a service
Communication protocolsHTTP, gRPCDubbo, no HTTP
Star countgithub starsgithub starsdtm 0.1 is released from 20210604 and under fast development

From the features' comparison above, if your language stack includes languages other than Java, then dtm is the one for you.If your language stack is Java, you can also choose to access dtm and use sub-transaction barrier technology to simplify your business development.

Installation

Add nuget package via the following command

dotnet add package Dtmcli

Configuration

There are two ways to configure

  1. Configure with setup action
services.AddDtmcli(x=>{// DTM server HTTP addressx.DtmUrl="http://localhost:36789";// request timeout for DTM server, unit is millisecondsx.DtmTimeout=10000;// request timeout for trans branch, unit is millisecondsx.BranchTimeout=10000;// barrier database type, mysql, postgres, sqlserverx.DBType="mysql";// barrier table namex.BarrierTableName="dtm_barrier.barrier";});
  1. Configure withIConfiguration
services.AddDtmcli(Configuration,"dtm");

And the configuration file

{"dtm": {"DtmUrl":"http://localhost:36789","DtmTimeout":10000,"BranchTimeout":10000,"DBType":"mysql","BarrierTableName":"dtm_barrier.barrier",  }}

Usage

SAGA pattern

publicclassMyBusi{privatereadonlyDtmcli.IDtmTransFactory_transFactory;publicMyBusi(Dtmcli.IDtmTransFactorytransFactory){this._transFactory=transFactory;}publicasyncTaskDoBusAsync(){vargid=Guid.NewGuid().ToString();varreq=newBusiReq{Amount=30};// NOTE: After DTM v1.12.2// when svc start with http or https, DTM server will send HTTP request to svc// when svc don't start with http or https,  DTM server will send gRPC request to svcvarsvc="http://localhost:5005";varsaga=_transFactory.NewSaga(gid);// Add sub-transactionsaga.Add(// URL of forward actionsvc+"/api/TransOut",// URL of compensating actionsvc+"/api/TransOutCompensate",// Arguments of actionsreq);saga.Add(svc+"/api/TransIn",svc+"/api/TransInCompensate",req);awaitsaga.Submit();}}

TCC pattern

publicclassMyBusi{privatereadonlyDtmcli.TccGlobalTransaction_globalTransaction;publicMyBusi(Dtmcli.TccGlobalTransactionglobalTransaction){this._globalTransaction=globalTransaction;}publicasyncTaskDoBusAsync(){vargid=Guid.NewGuid().ToString();varreq=newBusiReq{Amount=30};varsvc="http://localhost:5005";await_globalTransaction.Excecute(gid,async tcc=>{// Create tcc sub-transactionawaittcc.CallBranch(// Arguments of stagesreq,// URL of Try stagesvc+"/api/TransOutTry",// URL of Confirm stagesvc+"/api/TransOutConfirm",// URL of Cancel stagesvc+"/api/TransOutCancel");awaittcc.CallBranch(req,svc+"/api/TransInTry",svc+"/api/TransInConfirm",svc+"/api/TransInCancel");});}}

2-phase message pattern

publicclassMyBusi{privatereadonlyDtmcli.IDtmTransFactory_transFactory;publicMyBusi(Dtmcli.IDtmTransFactorytransFactory){this._transFactory=transFactory;}publicasyncTaskDoBusAsync(){vargid=Guid.NewGuid().ToString();varreq=newBusiReq{Amount=30};varsvc="http://localhost:5005";varmsg=_transFactory.NewMsg(gid);// Add sub-transactionmsg.Add(// URL of actionsvc+"/api/TransOut",// Arguments of actionreq);msg.Add(svc+"/api/TransIn",req);// Usage 1:// Send prepare messageawaitmsg.Prepare(svc+"/api/QueryPrepared");// Send submit messageawaitmsg.Submit();// Usage 2:using(varconn=GetDbConnection()){awaitmsg.DoAndSubmitDB(svc+"/api/QueryPrepared",conn,async tx=>{awaitconn.ExecuteAsync("insert ....",new{},tx);awaitconn.ExecuteAsync("update ....",new{},tx);awaitconn.ExecuteAsync("delete ....",new{},tx);});}}}

Complete example

Refer tohttps://github.com/dtm-labs/dtmcli-csharp-sample

Contact us

Wechat communication group

Add wechat friend with idyedf2008, or scan the OR code. Fill incsharp as verification.

yedf2008

About

The new client for dtm in csharp, including workflow, dtmcli, and dtmgrpc

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors12


[8]ページ先頭

©2009-2025 Movatter.jp