Dtmcli 1.2.0-alpha20220613151301

This is a prerelease version of Dtmcli.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Dtmcli --version 1.2.0-alpha20220613151301                
NuGet\Install-Package Dtmcli -Version 1.2.0-alpha20220613151301                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dtmcli" Version="1.2.0-alpha20220613151301" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dtmcli --version 1.2.0-alpha20220613151301                
#r "nuget: Dtmcli, 1.2.0-alpha20220613151301"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Dtmcli as a Cake Addin
#addin nuget:?package=Dtmcli&version=1.2.0-alpha20220613151301&prerelease

// Install Dtmcli as a Cake Tool
#tool nuget:?package=Dtmcli&version=1.2.0-alpha20220613151301&prerelease                

English | 简体中文

dtmcli-csharp

dtmcli-csharp is the C# client of Distributed Transaction Manager DTM 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_Test codecov

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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:

<img alt="function-picture" src="https://en.dtm.pub/assets/function.7d5618f8.png" height=250 />

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.

Features DTM Seata Remarks
Supported languages <span style="color:green">Golang, C#, Java, Python, PHP, and others</span> <span style="color:orange">Java</span> dtm allows easy access from a new language
Exception handling Sub-transaction barrier <span style="color:orange">manual</span> dtm solves idempotent transaction, hanging, null compensation
TCC <span style="color:green">✓</span> <span style="color:green">✓</span>
XA <span style="color:green">✓</span> <span style="color:green">✓</span>
AT <span style="color:orange">suggest XA</span> <span style="color:green">✓</span> AT is similar to XA with better performance but with dirty rollback
SAGA <span style="color:green">support concurrency</span> <span style="color:green">complicated state-machine mode</span> dtm's state-machine mode is being planned
Transactional Messaging <span style="color:green">✓</span> <span style="color:red">✗</span> dtm provides Transactional Messaging similar to RocketMQ
Multiple DBs in a service <span style="color:green">✓</span> <span style="color:red">✗</span>
Communication protocols <span style="color:green">HTTP, gRPC</span> <span style="color:green">Dubbo, no HTTP</span>
Star count <img src="https://img.shields.io/github/stars/dtm-labs/dtm.svg?style=social" alt="github stars"/> <img src="https://img.shields.io/github/stars/seata/seata.svg?style=social" alt="github stars"/> dtm 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 address
    x.DtmUrl = "http://localhost:36789";
    
    // request timeout for DTM server, unit is milliseconds
    x.DtmTimeout = 10000; 
    
    // request timeout for trans branch, unit is milliseconds
    x.BranchTimeout = 10000;
    
    // barrier database type, mysql, postgres, sqlserver
    x.DBType = "mysql";

    // barrier table name
    x.BarrierTableName = "dtm_barrier.barrier";
});
  1. Configure with IConfiguration
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

public class MyBusi
{ 
    private readonly Dtmcli.IDtmTransFactory _transFactory;

    public MyBusi(Dtmcli.IDtmTransFactory transFactory)
    {
        this._transFactory = transFactory;
    }

    public async Task DoBusAsync()
    {
        var gid = Guid.NewGuid().ToString();
        var req = new BusiReq {  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 svc
        var svc = "http://localhost:5005";

        var saga = _transFactory.NewSaga(gid);
        // Add sub-transaction
        saga.Add(
            // URL of forward action 
            svc + "/api/TransOut",
            
            // URL of compensating action
            svc + "/api/TransOutCompensate",

            // Arguments of actions
            req);
        saga.Add(
            svc + "/api/TransIn",
            svc + "/api/TransInCompensate",
            req);

        await saga.Submit();
    }
}

TCC pattern

public class MyBusi
{ 
    private readonly Dtmcli.TccGlobalTransaction _globalTransaction;

    public MyBusi(Dtmcli.TccGlobalTransaction globalTransaction)
    {
        this._globalTransaction = globalTransaction;
    }

    public async Task DoBusAsync()
    {
        var gid = Guid.NewGuid().ToString();
        var req = new BusiReq {  Amount = 30 };
        var svc = "http://localhost:5005";

        await _globalTransaction.Excecute(gid, async tcc =>
        {
            // Create tcc sub-transaction
            await tcc.CallBranch(
                // Arguments of stages
                req,

                // URL of Try stage
                svc + "/api/TransOutTry",

                // URL of Confirm stage
                svc + "/api/TransOutConfirm",

                 // URL of Cancel stage
                svc + "/api/TransOutCancel");

            await tcc.CallBranch(
                req,
                svc + "/api/TransInTry",
                svc + "/api/TransInConfirm",
                svc + "/api/TransInCancel");
        });
    }
}

2-phase message pattern

public class MyBusi
{ 
    private readonly Dtmcli.IDtmTransFactory _transFactory;

    public MyBusi(Dtmcli.IDtmTransFactory transFactory)
    {
        this._transFactory = transFactory;
    }

    public async Task DoBusAsync()
    {
        var gid = Guid.NewGuid().ToString();
        var req = new BusiReq {  Amount = 30 };
        var svc = "http://localhost:5005";

        var msg = _transFactory.NewMsg(gid);
        // Add sub-transaction
        msg.Add(
            // URL of action 
            svc + "/api/TransOut",

            // Arguments of action
            req);
        msg.Add(
            svc + "/api/TransIn",
            req);

        // Usage 1:
        // Send prepare message 
        await msg.Prepare(svc + "/api/QueryPrepared");
        // Send submit message
        await msg.Submit();

        // Usage 2:
        using (var conn = GetDbConnection())
        {
            await msg.DoAndSubmitDB(svc + "/api/QueryPrepared", conn, async tx => 
            {
                await conn.ExecuteAsync("insert ....", new { }, tx);
                await conn.ExecuteAsync("update ....", new { }, tx);
                await conn.ExecuteAsync("delete ....", new { }, tx);
            });
        }
    }
}

Complete example

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

Contact us

Wechat communication group

Add wechat friend with id yedf2008, or scan the OR code. Fill in csharp as verification.

yedf2008

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Dtmcli:

Package Downloads
DtmDapr

a c# client for distributed transaction framework dtm with Dapr utilities. 分布式事务管理器dtm的c#客户端,附带Dapr相关的工具类。

Dtmcli.EFCore

对Dtmcli的二次封装

Dtmworkflow

a c# client for distributed transaction framework dtm. 分布式事务管理器dtm的c#客户端

Cngot.Extensions.Saga

分布式事务

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0-alpha20240514080351 545 5/16/2024
1.5.0-alpha20240207010727 196 2/7/2024
1.5.0-alpha20240126005523 152 1/26/2024
1.5.0-alpha20230715065502 3,856 7/15/2023
1.5.0-alpha20230712141834 180 7/12/2023
1.5.0-alpha20230711003322 189 7/11/2023
1.5.0-alpha20230329144504 203 3/29/2023
1.5.0-alpha20230328002506 178 3/28/2023
1.4.0 13,373 3/23/2023
1.4.0-alpha20230323144415 214 3/23/2023
1.4.0-alpha20230322145505 205 3/22/2023
1.4.0-alpha20230315045153 160 3/15/2023
1.4.0-alpha20221208021220 240 12/8/2022
1.3.0 4,810 8/30/2022
1.3.0-alpha20221129091205 164 11/29/2022
1.3.0-alpha20221129031531 150 11/29/2022
1.3.0-alpha20220830143850 163 8/30/2022
1.2.0 1,771 6/13/2022
1.2.0-alpha20220829145424 136 8/29/2022
1.2.0-alpha20220829144633 163 8/29/2022
1.2.0-alpha20220828150913 164 8/28/2022
1.2.0-alpha20220822043149 166 8/22/2022
1.2.0-alpha20220819004738 161 8/19/2022
1.2.0-alpha20220613151301 180 6/13/2022
1.1.2 1,818 5/26/2022
1.1.2-alpha20220526153318 174 5/26/2022
1.1.2-alpha20220519145309 172 5/19/2022
1.1.1 465 5/14/2022
1.1.1-alpha20220514032637 162 5/14/2022
1.1.0 511 4/9/2022
1.1.0-alpha20220409030258 172 4/9/2022
1.0.0 702 3/1/2022
1.0.0-alpha20220329140755 186 3/29/2022
1.0.0-alpha20220328161232 185 3/28/2022
1.0.0-alpha20220328161158 188 3/28/2022
1.0.0-alpha20220301143642 177 3/1/2022
1.0.0-alpha20220223043821 171 2/23/2022
1.0.0-alpha20220221134440 175 2/21/2022
0.5.0 483 2/19/2022
0.5.0-alpha20220219075114 177 2/19/2022
0.5.0-alpha20220218100129 165 2/18/2022
0.5.0-alpha20220216140508 181 2/16/2022
0.5.0-alpha20220213045321 192 2/13/2022
0.5.0-alpha20220213035502 157 2/13/2022
0.5.0-alpha20220213014814 158 2/13/2022
0.5.0-alpha20220210044934 171 2/10/2022
0.4.0 513 2/5/2022
0.4.0-alpha20220209092027 196 2/9/2022
0.4.0-alpha20220205130133 180 2/5/2022
0.4.0-alpha20220205025645 187 2/5/2022
0.4.0-alpha20220203054543 194 2/3/2022
0.4.0-alpha20220203035129 200 2/3/2022
0.4.0-alpha20220131041847 184 1/31/2022
0.4.0-alpha20220128011854 192 1/28/2022
0.4.0-alpha20220125123820 190 1/25/2022
0.3.0 623 1/21/2022
0.3.0-alpha20220125123431 185 1/25/2022
0.3.0-alpha20220121003512 175 1/21/2022
0.3.0-alpha20220120125355 204 1/20/2022
0.3.0-alpha20220120061225 185 1/20/2022
0.3.0-alpha20220119151323 201 1/19/2022
0.3.0-alpha20220119121047 194 1/19/2022
0.3.0-alpha20220119102945 173 1/19/2022
0.2.0.1910 403 8/1/2021
0.2.0-preview 263 8/1/2021
0.1.0-preview 263 7/30/2021