Dtmcli 1.1.2-alpha20220519145309

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.1.2-alpha20220519145309                
NuGet\Install-Package Dtmcli -Version 1.1.2-alpha20220519145309                
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.1.2-alpha20220519145309" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dtmcli --version 1.1.2-alpha20220519145309                
#r "nuget: Dtmcli, 1.1.2-alpha20220519145309"                
#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.1.2-alpha20220519145309&prerelease

// Install Dtmcli as a Cake Tool
#tool nuget:?package=Dtmcli&version=1.1.2-alpha20220519145309&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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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-alpha20241227095141 4 12/27/2024
1.5.0-alpha20241218010541 106 12/18/2024
1.5.0-alpha20241218010500 89 12/18/2024
1.5.0-alpha20241218010339 82 12/18/2024
1.5.0-alpha20241211030409 107 12/11/2024
1.5.0-alpha20241210035458 106 12/10/2024
1.5.0-alpha20241207152033 98 12/7/2024
1.5.0-alpha20241207151914 87 12/7/2024
1.5.0-alpha20241207151735 106 12/7/2024
1.5.0-alpha20241207151531 98 12/7/2024
1.5.0-alpha20241207151035 114 12/7/2024
1.5.0-alpha20240514080351 593 5/16/2024
1.5.0-alpha20240207010727 198 2/7/2024
1.5.0-alpha20240126005523 154 1/26/2024
1.5.0-alpha20230715065502 4,073 7/15/2023
1.5.0-alpha20230712141834 182 7/12/2023
1.5.0-alpha20230711003322 191 7/11/2023
1.5.0-alpha20230329144504 205 3/29/2023
1.5.0-alpha20230328002506 180 3/28/2023
1.4.0 14,356 3/23/2023
1.4.0-alpha20230323144415 216 3/23/2023
1.4.0-alpha20230322145505 207 3/22/2023
1.4.0-alpha20230315045153 162 3/15/2023
1.4.0-alpha20221208021220 242 12/8/2022
1.3.0 4,846 8/30/2022
1.3.0-alpha20221129091205 166 11/29/2022
1.3.0-alpha20221129031531 152 11/29/2022
1.3.0-alpha20220830143850 165 8/30/2022
1.2.0 1,779 6/13/2022
1.2.0-alpha20220829145424 138 8/29/2022
1.2.0-alpha20220829144633 165 8/29/2022
1.2.0-alpha20220828150913 166 8/28/2022
1.2.0-alpha20220822043149 168 8/22/2022
1.2.0-alpha20220819004738 163 8/19/2022
1.2.0-alpha20220613151301 182 6/13/2022
1.1.2 1,824 5/26/2022
1.1.2-alpha20220526153318 176 5/26/2022
1.1.2-alpha20220519145309 174 5/19/2022
1.1.1 471 5/14/2022
1.1.1-alpha20220514032637 164 5/14/2022
1.1.0 517 4/9/2022
1.1.0-alpha20220409030258 174 4/9/2022
1.0.0 710 3/1/2022
1.0.0-alpha20220329140755 188 3/29/2022
1.0.0-alpha20220328161232 187 3/28/2022
1.0.0-alpha20220328161158 190 3/28/2022
1.0.0-alpha20220301143642 179 3/1/2022
1.0.0-alpha20220223043821 173 2/23/2022
1.0.0-alpha20220221134440 177 2/21/2022
0.5.0 489 2/19/2022
0.5.0-alpha20220219075114 179 2/19/2022
0.5.0-alpha20220218100129 167 2/18/2022
0.5.0-alpha20220216140508 183 2/16/2022
0.5.0-alpha20220213045321 194 2/13/2022
0.5.0-alpha20220213035502 159 2/13/2022
0.5.0-alpha20220213014814 160 2/13/2022
0.5.0-alpha20220210044934 173 2/10/2022
0.4.0 519 2/5/2022
0.4.0-alpha20220209092027 198 2/9/2022
0.4.0-alpha20220205130133 182 2/5/2022
0.4.0-alpha20220205025645 189 2/5/2022
0.4.0-alpha20220203054543 196 2/3/2022
0.4.0-alpha20220203035129 202 2/3/2022
0.4.0-alpha20220131041847 186 1/31/2022
0.4.0-alpha20220128011854 194 1/28/2022
0.4.0-alpha20220125123820 192 1/25/2022
0.3.0 634 1/21/2022
0.3.0-alpha20220125123431 187 1/25/2022
0.3.0-alpha20220121003512 179 1/21/2022
0.3.0-alpha20220120125355 206 1/20/2022
0.3.0-alpha20220120061225 187 1/20/2022
0.3.0-alpha20220119151323 203 1/19/2022
0.3.0-alpha20220119121047 196 1/19/2022
0.3.0-alpha20220119102945 177 1/19/2022
0.2.0.1910 409 8/1/2021
0.2.0-preview 265 8/1/2021
0.1.0-preview 265 7/30/2021