mirror of https://github.com/dtm-labs/dtm.git
csharpjavadistributed-transactionsdtmgogolangmicroservicenodejsphpdatabasesagaseatatcctransactiontransactionsxapythondistributed
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
941 B
37 lines
941 B
/*
|
|
* Copyright (c) 2021 yedf. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style
|
|
* license that can be found in the LICENSE file.
|
|
*/
|
|
|
|
package examples
|
|
|
|
import (
|
|
context "context"
|
|
|
|
"github.com/yedf/dtm/dtmcli/logger"
|
|
"github.com/yedf/dtm/dtmgrpc"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
func init() {
|
|
addSample("grpc_xa", func() string {
|
|
gid := dtmgrpc.MustGenGid(DtmGrpcServer)
|
|
req := &BusiReq{Amount: 30}
|
|
err := XaGrpcClient.XaGlobalTransaction(gid, func(xa *dtmgrpc.XaGrpc) error {
|
|
r := &emptypb.Empty{}
|
|
err := xa.CallBranch(req, BusiGrpc+"/examples.Busi/TransOutXa", r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = xa.CallBranch(req, BusiGrpc+"/examples.Busi/TransInXa", r)
|
|
return err
|
|
})
|
|
logger.FatalIfError(err)
|
|
return gid
|
|
})
|
|
}
|
|
|
|
func (s *busiServer) XaNotify(ctx context.Context, in *emptypb.Empty) (*emptypb.Empty, error) {
|
|
return XaGrpcClient.HandleCallback(ctx)
|
|
}
|
|
|