sample use register

This commit is contained in:
yedf2 2021-08-11 20:54:20 +08:00
parent 693d6d56ea
commit cef6a92463
18 changed files with 382 additions and 278 deletions

View File

@ -42,27 +42,9 @@ func main() {
// 下面是各类的例子
examples.BaseAppStartup()
examples.GrpcStartup()
if os.Args[1] == "xa" { // 启动xa示例
examples.XaFireRequest()
} else if os.Args[1] == "saga" { // 启动saga示例
examples.SagaFireRequest()
} else if os.Args[1] == "tcc" { // 启动tcc示例
examples.TccFireRequestNested()
} else if os.Args[1] == "msg" { // 启动msg示例
examples.MsgFireRequest()
} else if os.Args[1] == "msg_grpc" { // 启动msg示例
examples.MsgGrpcFireRequest()
} else if os.Args[1] == "all" { // 运行所有示例
examples.SagaFireRequest()
examples.TccFireRequestNested()
examples.XaFireRequest()
examples.MsgFireRequest()
} else if os.Args[1] == "saga_barrier" {
examples.SagaBarrierFireRequest()
} else if os.Args[1] == "tcc_barrier" {
examples.TccBarrierFireRequest()
} else {
dtmcli.LogRedf("unknown arg: %s", os.Args[1])
}
fn := examples.Samples[os.Args[1]]
dtmcli.LogIfFatalf(fn == nil, "no sample name for %s", os.Args[1])
fn()
wait()
}

View File

@ -104,6 +104,53 @@ func (x *DtmRequest) GetData() string {
return ""
}
type DtmGidReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"`
}
func (x *DtmGidReply) Reset() {
*x = DtmGidReply{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DtmGidReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DtmGidReply) ProtoMessage() {}
func (x *DtmGidReply) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DtmGidReply.ProtoReflect.Descriptor instead.
func (*DtmGidReply) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{1}
}
func (x *DtmGidReply) GetGid() string {
if x != nil {
return x.Gid
}
return ""
}
// BranchInfo 事务分支信息
type BranchInfo struct {
state protoimpl.MessageState
@ -119,7 +166,7 @@ type BranchInfo struct {
func (x *BranchInfo) Reset() {
*x = BranchInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -132,7 +179,7 @@ func (x *BranchInfo) String() string {
func (*BranchInfo) ProtoMessage() {}
func (x *BranchInfo) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -145,7 +192,7 @@ func (x *BranchInfo) ProtoReflect() protoreflect.Message {
// Deprecated: Use BranchInfo.ProtoReflect.Descriptor instead.
func (*BranchInfo) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{1}
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{2}
}
func (x *BranchInfo) GetGid() string {
@ -191,7 +238,7 @@ type DtmTccBranchRequest struct {
func (x *DtmTccBranchRequest) Reset() {
*x = DtmTccBranchRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -204,7 +251,7 @@ func (x *DtmTccBranchRequest) String() string {
func (*DtmTccBranchRequest) ProtoMessage() {}
func (x *DtmTccBranchRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -217,7 +264,7 @@ func (x *DtmTccBranchRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use DtmTccBranchRequest.ProtoReflect.Descriptor instead.
func (*DtmTccBranchRequest) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{2}
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{3}
}
func (x *DtmTccBranchRequest) GetInfo() *BranchInfo {
@ -269,7 +316,7 @@ type DtmXaBranchRequest struct {
func (x *DtmXaBranchRequest) Reset() {
*x = DtmXaBranchRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -282,7 +329,7 @@ func (x *DtmXaBranchRequest) String() string {
func (*DtmXaBranchRequest) ProtoMessage() {}
func (x *DtmXaBranchRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -295,7 +342,7 @@ func (x *DtmXaBranchRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use DtmXaBranchRequest.ProtoReflect.Descriptor instead.
func (*DtmXaBranchRequest) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{3}
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{4}
}
func (x *DtmXaBranchRequest) GetInfo() *BranchInfo {
@ -333,7 +380,7 @@ type BusiRequest struct {
func (x *BusiRequest) Reset() {
*x = BusiRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -346,7 +393,7 @@ func (x *BusiRequest) String() string {
func (*BusiRequest) ProtoMessage() {}
func (x *BusiRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -359,7 +406,7 @@ func (x *BusiRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use BusiRequest.ProtoReflect.Descriptor instead.
func (*BusiRequest) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{4}
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{5}
}
func (x *BusiRequest) GetInfo() *BranchInfo {
@ -395,7 +442,7 @@ type BusiReply struct {
func (x *BusiReply) Reset() {
*x = BusiReply{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -408,7 +455,7 @@ func (x *BusiReply) String() string {
func (*BusiReply) ProtoMessage() {}
func (x *BusiReply) ProtoReflect() protoreflect.Message {
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[5]
mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -421,7 +468,7 @@ func (x *BusiReply) ProtoReflect() protoreflect.Message {
// Deprecated: Use BusiReply.ProtoReflect.Descriptor instead.
func (*BusiReply) Descriptor() ([]byte, []int) {
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{5}
return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{6}
}
func (x *BusiReply) GetBusiData() []byte {
@ -447,64 +494,69 @@ var file_dtmgrpc_dtmgrpc_proto_rawDesc = []byte{
0x65, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74,
0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75,
0x6c, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x78, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68,
0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54,
0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73,
0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44,
0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65,
0x22, 0x9e, 0x01, 0x0a, 0x13, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, 0x63,
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x1f, 0x0a, 0x0b, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64,
0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x22, 0x78, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63,
0x68, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73,
0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e,
0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49,
0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49,
0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x18,
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70,
0x65, 0x22, 0x9e, 0x01, 0x0a, 0x13, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e,
0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66,
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e,
0x66, 0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10,
0x0a, 0x03, 0x54, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x54, 0x72, 0x79,
0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x43, 0x61,
0x6e, 0x63, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x43, 0x61, 0x6e, 0x63,
0x65, 0x6c, 0x22, 0x71, 0x0a, 0x12, 0x44, 0x74, 0x6d, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63,
0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f,
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63,
0x2e, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66,
0x6f, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a,
0x03, 0x54, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x54, 0x72, 0x79, 0x12,
0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x07, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x43, 0x61, 0x6e,
0x63, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x43, 0x61, 0x6e, 0x63, 0x65,
0x6c, 0x22, 0x71, 0x0a, 0x12, 0x44, 0x74, 0x6d, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e,
0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f,
0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06,
0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4e, 0x6f,
0x74, 0x69, 0x66, 0x79, 0x22, 0x64, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x72, 0x61, 0x6e,
0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03,
0x44, 0x74, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x1a,
0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c,
0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x22, 0x27, 0x0a, 0x09, 0x42, 0x75,
0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44,
0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44,
0x61, 0x74, 0x61, 0x32, 0xc8, 0x02, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x37, 0x0a, 0x06, 0x53,
0x75, 0x62, 0x6d, 0x69, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e,
0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70,
0x74, 0x79, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x12,
0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71,
0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a,
0x06, 0x4e, 0x6f, 0x74, 0x69, 0x66, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4e,
0x6f, 0x74, 0x69, 0x66, 0x79, 0x22, 0x64, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x72, 0x61,
0x6e, 0x63, 0x68, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a,
0x03, 0x44, 0x74, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x12,
0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0c, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69, 0x44, 0x61, 0x74, 0x61, 0x22, 0x27, 0x0a, 0x09, 0x42,
0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x75, 0x73, 0x69,
0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x42, 0x75, 0x73, 0x69,
0x44, 0x61, 0x74, 0x61, 0x32, 0x82, 0x03, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x38, 0x0a, 0x06,
0x4e, 0x65, 0x77, 0x47, 0x69, 0x64, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14,
0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x47, 0x69, 0x64, 0x52,
0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x53, 0x75, 0x62, 0x6d, 0x69, 0x74,
0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12,
0x38, 0x0a, 0x07, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d,
0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x36, 0x0a, 0x05, 0x41, 0x62, 0x6f,
0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22,
0x00, 0x12, 0x4b, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x54, 0x63, 0x63,
0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x1c, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63,
0x2e, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x36,
0x0a, 0x05, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67,
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45,
0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x4b, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74,
0x65, 0x72, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x1c, 0x2e, 0x64, 0x74,
0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x63, 0x63, 0x42, 0x72, 0x61, 0x6e,
0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74,
0x79, 0x22, 0x00, 0x12, 0x49, 0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x58,
0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x12, 0x1b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70,
0x63, 0x2e, 0x44, 0x74, 0x6d, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x1d,
0x5a, 0x1b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x65, 0x64,
0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x49,
0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x58, 0x61, 0x42, 0x72, 0x61, 0x6e,
0x63, 0x68, 0x12, 0x1b, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d,
0x58, 0x61, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42, 0x1d, 0x5a, 0x1b, 0x67, 0x69, 0x74,
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d,
0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -519,32 +571,35 @@ func file_dtmgrpc_dtmgrpc_proto_rawDescGZIP() []byte {
return file_dtmgrpc_dtmgrpc_proto_rawDescData
}
var file_dtmgrpc_dtmgrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_dtmgrpc_dtmgrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_dtmgrpc_dtmgrpc_proto_goTypes = []interface{}{
(*DtmRequest)(nil), // 0: dtmgrpc.DtmRequest
(*BranchInfo)(nil), // 1: dtmgrpc.BranchInfo
(*DtmTccBranchRequest)(nil), // 2: dtmgrpc.DtmTccBranchRequest
(*DtmXaBranchRequest)(nil), // 3: dtmgrpc.DtmXaBranchRequest
(*BusiRequest)(nil), // 4: dtmgrpc.BusiRequest
(*BusiReply)(nil), // 5: dtmgrpc.BusiReply
(*emptypb.Empty)(nil), // 6: google.protobuf.Empty
(*DtmGidReply)(nil), // 1: dtmgrpc.DtmGidReply
(*BranchInfo)(nil), // 2: dtmgrpc.BranchInfo
(*DtmTccBranchRequest)(nil), // 3: dtmgrpc.DtmTccBranchRequest
(*DtmXaBranchRequest)(nil), // 4: dtmgrpc.DtmXaBranchRequest
(*BusiRequest)(nil), // 5: dtmgrpc.BusiRequest
(*BusiReply)(nil), // 6: dtmgrpc.BusiReply
(*emptypb.Empty)(nil), // 7: google.protobuf.Empty
}
var file_dtmgrpc_dtmgrpc_proto_depIdxs = []int32{
1, // 0: dtmgrpc.DtmTccBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
1, // 1: dtmgrpc.DtmXaBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
1, // 2: dtmgrpc.BusiRequest.Info:type_name -> dtmgrpc.BranchInfo
0, // 3: dtmgrpc.Dtm.Submit:input_type -> dtmgrpc.DtmRequest
0, // 4: dtmgrpc.Dtm.Prepare:input_type -> dtmgrpc.DtmRequest
0, // 5: dtmgrpc.Dtm.Abort:input_type -> dtmgrpc.DtmRequest
2, // 6: dtmgrpc.Dtm.RegisterTccBranch:input_type -> dtmgrpc.DtmTccBranchRequest
3, // 7: dtmgrpc.Dtm.RegisterXaBranch:input_type -> dtmgrpc.DtmXaBranchRequest
6, // 8: dtmgrpc.Dtm.Submit:output_type -> google.protobuf.Empty
6, // 9: dtmgrpc.Dtm.Prepare:output_type -> google.protobuf.Empty
6, // 10: dtmgrpc.Dtm.Abort:output_type -> google.protobuf.Empty
6, // 11: dtmgrpc.Dtm.RegisterTccBranch:output_type -> google.protobuf.Empty
6, // 12: dtmgrpc.Dtm.RegisterXaBranch:output_type -> google.protobuf.Empty
8, // [8:13] is the sub-list for method output_type
3, // [3:8] is the sub-list for method input_type
2, // 0: dtmgrpc.DtmTccBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
2, // 1: dtmgrpc.DtmXaBranchRequest.Info:type_name -> dtmgrpc.BranchInfo
2, // 2: dtmgrpc.BusiRequest.Info:type_name -> dtmgrpc.BranchInfo
7, // 3: dtmgrpc.Dtm.NewGid:input_type -> google.protobuf.Empty
0, // 4: dtmgrpc.Dtm.Submit:input_type -> dtmgrpc.DtmRequest
0, // 5: dtmgrpc.Dtm.Prepare:input_type -> dtmgrpc.DtmRequest
0, // 6: dtmgrpc.Dtm.Abort:input_type -> dtmgrpc.DtmRequest
3, // 7: dtmgrpc.Dtm.RegisterTccBranch:input_type -> dtmgrpc.DtmTccBranchRequest
4, // 8: dtmgrpc.Dtm.RegisterXaBranch:input_type -> dtmgrpc.DtmXaBranchRequest
1, // 9: dtmgrpc.Dtm.NewGid:output_type -> dtmgrpc.DtmGidReply
7, // 10: dtmgrpc.Dtm.Submit:output_type -> google.protobuf.Empty
7, // 11: dtmgrpc.Dtm.Prepare:output_type -> google.protobuf.Empty
7, // 12: dtmgrpc.Dtm.Abort:output_type -> google.protobuf.Empty
7, // 13: dtmgrpc.Dtm.RegisterTccBranch:output_type -> google.protobuf.Empty
7, // 14: dtmgrpc.Dtm.RegisterXaBranch:output_type -> google.protobuf.Empty
9, // [9:15] is the sub-list for method output_type
3, // [3:9] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
@ -569,7 +624,7 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BranchInfo); i {
switch v := v.(*DtmGidReply); i {
case 0:
return &v.state
case 1:
@ -581,7 +636,7 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmTccBranchRequest); i {
switch v := v.(*BranchInfo); i {
case 0:
return &v.state
case 1:
@ -593,7 +648,7 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmXaBranchRequest); i {
switch v := v.(*DtmTccBranchRequest); i {
case 0:
return &v.state
case 1:
@ -605,7 +660,7 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiRequest); i {
switch v := v.(*DtmXaBranchRequest); i {
case 0:
return &v.state
case 1:
@ -617,6 +672,18 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_dtmgrpc_dtmgrpc_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiReply); i {
case 0:
return &v.state
@ -635,7 +702,7 @@ func file_dtmgrpc_dtmgrpc_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_dtmgrpc_dtmgrpc_proto_rawDesc,
NumEnums: 0,
NumMessages: 6,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -7,6 +7,7 @@ package dtmgrpc;
// The dtm service definition.
service Dtm {
rpc NewGid(google.protobuf.Empty) returns (DtmGidReply) {}
rpc Submit(DtmRequest) returns (google.protobuf.Empty) {}
rpc Prepare(DtmRequest) returns (google.protobuf.Empty) {}
rpc Abort(DtmRequest) returns (google.protobuf.Empty) {}
@ -26,18 +27,9 @@ message DtmRequest {
string Data = 5;
}
/*
"gid": t.Gid,
"branch_id": branchID,
"trans_type": "tcc",
"status": "prepared",
"data": string(MustMarshal(body)),
"try": tryURL,
"confirm": confirmURL,
"cancel": cancelURL,
*/
message DtmGidReply {
string Gid = 1;
}
// BranchInfo
message BranchInfo {
string Gid = 1;

View File

@ -19,6 +19,7 @@ const _ = grpc.SupportPackageIsVersion7
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type DtmClient interface {
NewGid(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*DtmGidReply, error)
Submit(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
Prepare(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
Abort(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
@ -34,6 +35,15 @@ func NewDtmClient(cc grpc.ClientConnInterface) DtmClient {
return &dtmClient{cc}
}
func (c *dtmClient) NewGid(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*DtmGidReply, error) {
out := new(DtmGidReply)
err := c.cc.Invoke(ctx, "/dtmgrpc.Dtm/NewGid", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *dtmClient) Submit(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/dtmgrpc.Dtm/Submit", in, out, opts...)
@ -83,6 +93,7 @@ func (c *dtmClient) RegisterXaBranch(ctx context.Context, in *DtmXaBranchRequest
// All implementations must embed UnimplementedDtmServer
// for forward compatibility
type DtmServer interface {
NewGid(context.Context, *emptypb.Empty) (*DtmGidReply, error)
Submit(context.Context, *DtmRequest) (*emptypb.Empty, error)
Prepare(context.Context, *DtmRequest) (*emptypb.Empty, error)
Abort(context.Context, *DtmRequest) (*emptypb.Empty, error)
@ -95,6 +106,9 @@ type DtmServer interface {
type UnimplementedDtmServer struct {
}
func (UnimplementedDtmServer) NewGid(context.Context, *emptypb.Empty) (*DtmGidReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method NewGid not implemented")
}
func (UnimplementedDtmServer) Submit(context.Context, *DtmRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Submit not implemented")
}
@ -123,6 +137,24 @@ func RegisterDtmServer(s grpc.ServiceRegistrar, srv DtmServer) {
s.RegisterService(&Dtm_ServiceDesc, srv)
}
func _Dtm_NewGid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(emptypb.Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DtmServer).NewGid(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/dtmgrpc.Dtm/NewGid",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DtmServer).NewGid(ctx, req.(*emptypb.Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Dtm_Submit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DtmRequest)
if err := dec(in); err != nil {
@ -220,6 +252,10 @@ var Dtm_ServiceDesc = grpc.ServiceDesc{
ServiceName: "dtmgrpc.Dtm",
HandlerType: (*DtmServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "NewGid",
Handler: _Dtm_NewGid_Handler,
},
{
MethodName: "Submit",
Handler: _Dtm_Submit_Handler,

View File

@ -9,6 +9,7 @@ import (
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
)
var clients = map[string]*grpc.ClientConn{}
@ -39,6 +40,14 @@ func MustGetDtmClient(grpcServer string) DtmClient {
return NewDtmClient(MustGetGrpcConn(grpcServer))
}
// MustGenGid 1
func MustGenGid(grpcServer string) string {
dc := MustGetDtmClient(grpcServer)
r, err := dc.NewGid(context.Background(), &emptypb.Empty{})
dtmcli.E2P(err)
return r.Gid
}
// GetServerAndMethod 将grpc的url分解为server和method
func GetServerAndMethod(grpcURL string) (string, string) {
fs := strings.Split(grpcURL, "/")

View File

@ -14,6 +14,10 @@ type dtmServer struct {
pb.UnimplementedDtmServer
}
func (s *dtmServer) NewGid(ctx context.Context, in *emptypb.Empty) (*dtmgrpc.DtmGidReply, error) {
return &dtmgrpc.DtmGidReply{Gid: GenGid()}, nil
}
func (s *dtmServer) Submit(ctx context.Context, in *pb.DtmRequest) (*emptypb.Empty, error) {
r, err := svcSubmit(TransFromDtmRequest(in), in.WaitResult)
return &emptypb.Empty{}, dtmgrpc.Result2Error(r, err)

View File

@ -36,3 +36,13 @@ func PopulateDB(skipDrop bool) {
file = fmt.Sprintf("%s/../dtmcli/barrier.%s.sql", common.GetCurrentCodeDir(), config.DB["driver"])
RunSQLScript(config.DB, file, skipDrop)
}
// Samples 所有的示例都会注册到这里
var Samples = map[string]func() string{}
func addSample(name string, fn func() string) {
if Samples[name] != nil {
dtmcli.LogFatalf("sample %s duplicated", name)
}
Samples[name] = fn
}

View File

@ -5,13 +5,15 @@ import (
dtmgrpc "github.com/yedf/dtm/dtmgrpc"
)
// MsgGrpcFireRequest 1
func MsgGrpcFireRequest() string {
req := dtmcli.MustMarshal(&TransReq{Amount: 30})
msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, dtmcli.MustGenGid(DtmServer)).
Add(BusiGrpc+"/examples.Busi/TransOut", req).
Add(BusiGrpc+"/examples.Busi/TransIn", req)
err := msg.Submit()
dtmcli.FatalIfError(err)
return msg.Gid
func init() {
addSample("grpc_msg", func() string {
req := dtmcli.MustMarshal(&TransReq{Amount: 30})
gid := dtmgrpc.MustGenGid(DtmGrpcServer)
msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, gid).
Add(BusiGrpc+"/examples.Busi/TransOut", req).
Add(BusiGrpc+"/examples.Busi/TransIn", req)
err := msg.Submit()
dtmcli.FatalIfError(err)
return msg.Gid
})
}

19
examples/grpc_saga.go Normal file
View File

@ -0,0 +1,19 @@
package examples
import (
"github.com/yedf/dtm/dtmcli"
dtmgrpc "github.com/yedf/dtm/dtmgrpc"
)
func init() {
addSample("grpc_saga", func() string {
req := dtmcli.MustMarshal(&TransReq{Amount: 30})
gid := dtmgrpc.MustGenGid(DtmGrpcServer)
msg := dtmgrpc.NewSaga(DtmGrpcServer, gid).
Add(BusiGrpc+"/examples.Busi/TransOut", BusiGrpc+"/examples.Busi/TransOutRevert", req).
Add(BusiGrpc+"/examples.Busi/TransIn", BusiGrpc+"/examples.Busi/TransOutRevert", req)
err := msg.Submit()
dtmcli.FatalIfError(err)
return msg.Gid
})
}

View File

@ -16,25 +16,23 @@ func init() {
setupFuncs["XaGrpcSetup"] = func(app *gin.Engine) {
XaGrpcClient = dtmgrpc.NewXaGrpcClient(DtmGrpcServer, config.DB, BusiGrpc+"/examples.Busi/XaNotify")
}
addSample("grpc_xa", func() string {
gid := dtmgrpc.MustGenGid(DtmGrpcServer)
busiData := dtmcli.MustMarshal(&TransReq{Amount: 30})
err := XaGrpcClient.XaGlobalTransaction(gid, func(xa *dtmgrpc.XaGrpc) error {
_, err := xa.CallBranch(busiData, BusiGrpc+"/examples.Busi/TransOutXa")
if err != nil {
return err
}
_, err = xa.CallBranch(busiData, BusiGrpc+"/examples.Busi/TransInXa")
return err
})
dtmcli.FatalIfError(err)
return gid
})
}
func (s *busiServer) XaNotify(ctx context.Context, in *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
err := XaGrpcClient.HandleCallback(in.Info.Gid, in.Info.BranchID, in.Info.BranchType)
return &emptypb.Empty{}, dtmgrpc.Result2Error(nil, err)
}
// XaGrpcFireRequest 注册全局XA事务调用XA的分支
func XaGrpcFireRequest() string {
gid := dtmcli.MustGenGid(DtmServer)
busiData := dtmcli.MustMarshal(&TransReq{Amount: 30})
err := XaGrpcClient.XaGlobalTransaction(gid, func(xa *dtmgrpc.XaGrpc) error {
_, err := xa.CallBranch(busiData, BusiGrpc+"/examples.Busi/TransOutXa")
if err != nil {
return err
}
_, err = xa.CallBranch(busiData, BusiGrpc+"/examples.Busi/TransInXa")
return err
})
dtmcli.FatalIfError(err)
return gid
}

View File

@ -4,17 +4,18 @@ import (
"github.com/yedf/dtm/dtmcli"
)
// MsgFireRequest 1
func MsgFireRequest() string {
dtmcli.Logf("a busi transaction begin")
req := &TransReq{Amount: 30}
msg := dtmcli.NewMsg(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", req).
Add(Busi+"/TransIn", req)
err := msg.Prepare(Busi + "/TransQuery")
dtmcli.FatalIfError(err)
dtmcli.Logf("busi trans submit")
err = msg.Submit()
dtmcli.FatalIfError(err)
return msg.Gid
func init() {
addSample("msg", func() string {
dtmcli.Logf("a busi transaction begin")
req := &TransReq{Amount: 30}
msg := dtmcli.NewMsg(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", req).
Add(Busi+"/TransIn", req)
err := msg.Prepare(Busi + "/TransQuery")
dtmcli.FatalIfError(err)
dtmcli.Logf("busi trans submit")
err = msg.Submit()
dtmcli.FatalIfError(err)
return msg.Gid
})
}

View File

@ -4,20 +4,21 @@ import (
"github.com/yedf/dtm/dtmcli"
)
// SagaFireRequest 1
func SagaFireRequest() string {
dtmcli.Logf("a saga busi transaction begin")
req := &TransReq{
Amount: 30,
TransInResult: "SUCCESS",
TransOutResult: "SUCCESS",
}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
dtmcli.Logf("saga busi trans submit")
err := saga.Submit()
dtmcli.Logf("result gid is: %s", saga.Gid)
dtmcli.FatalIfError(err)
return saga.Gid
func init() {
addSample("saga", func() string {
dtmcli.Logf("a saga busi transaction begin")
req := &TransReq{
Amount: 30,
TransInResult: "SUCCESS",
TransOutResult: "SUCCESS",
}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
dtmcli.Logf("saga busi trans submit")
err := saga.Submit()
dtmcli.Logf("result gid is: %s", saga.Gid)
dtmcli.FatalIfError(err)
return saga.Gid
})
}

View File

@ -8,19 +8,6 @@ import (
"github.com/yedf/dtm/dtmcli"
)
// SagaBarrierFireRequest 1
func SagaBarrierFireRequest() string {
dtmcli.Logf("a busi transaction begin")
req := &TransReq{Amount: 30}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
dtmcli.Logf("busi trans submit")
err := saga.Submit()
dtmcli.FatalIfError(err)
return saga.Gid
}
func init() {
setupFuncs["SagaBarrierSetup"] = func(app *gin.Engine) {
app.POST(BusiAPI+"/SagaBTransIn", common.WrapHandler(sagaBarrierTransIn))
@ -29,6 +16,17 @@ func init() {
app.POST(BusiAPI+"/SagaBTransOutCompensate", common.WrapHandler(sagaBarrierTransOutCompensate))
dtmcli.Logf("examples listening at %d", BusiPort)
}
addSample("saga_barrier", func() string {
dtmcli.Logf("a busi transaction begin")
req := &TransReq{Amount: 30}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/SagaBTransOut", Busi+"/SagaBTransOutCompensate", req).
Add(Busi+"/SagaBTransIn", Busi+"/SagaBTransInCompensate", req)
dtmcli.Logf("busi trans submit")
err := saga.Submit()
dtmcli.FatalIfError(err)
return saga.Gid
})
}
func sagaBarrierAdjustBalance(sdb *sql.Tx, uid int, amount int) (interface{}, error) {

View File

@ -4,20 +4,21 @@ import (
"github.com/yedf/dtm/dtmcli"
)
// SagaWaitFireRequest 1
func SagaWaitFireRequest() string {
dtmcli.Logf("a saga busi transaction begin")
req := &TransReq{
Amount: 30,
TransInResult: "SUCCESS",
TransOutResult: "SUCCESS",
}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
saga.WaitResult = true // 设置为等待结果模式后面的submit调用会等待服务器处理这个事务。如果Submit正常返回那么整个全局事务已成功完成
err := saga.Submit()
dtmcli.Logf("result gid is: %s", saga.Gid)
dtmcli.FatalIfError(err)
return saga.Gid
func init() {
addSample("saga_wait", func() string {
dtmcli.Logf("a saga busi transaction begin")
req := &TransReq{
Amount: 30,
TransInResult: "SUCCESS",
TransOutResult: "SUCCESS",
}
saga := dtmcli.NewSaga(DtmServer, dtmcli.MustGenGid(DtmServer)).
Add(Busi+"/TransOut", Busi+"/TransOutRevert", req).
Add(Busi+"/TransIn", Busi+"/TransInRevert", req)
saga.WaitResult = true // 设置为等待结果模式后面的submit调用会等待服务器处理这个事务。如果Submit正常返回那么整个全局事务已成功完成
err := saga.Submit()
dtmcli.Logf("result gid is: %s", saga.Gid)
dtmcli.FatalIfError(err)
return saga.Gid
})
}

View File

@ -16,33 +16,29 @@ func init() {
return tcc.CallBranch(&TransReq{Amount: reqFrom(c).Amount}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
}))
}
}
// TccFireRequestNested 1
func TccFireRequestNested() string {
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransInTccParent", Busi+"/TransInConfirm", Busi+"/TransInRevert")
addSample("tcc_nested", func() string {
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransInTccParent", Busi+"/TransInConfirm", Busi+"/TransInRevert")
})
dtmcli.FatalIfError(err)
return gid
})
dtmcli.FatalIfError(err)
return gid
}
// TccFireRequest 1
func TccFireRequest() string {
dtmcli.Logf("tcc simple transaction begin")
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
addSample("tcc", func() string {
dtmcli.Logf("tcc simple transaction begin")
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOut", Busi+"/TransOutConfirm", Busi+"/TransOutRevert")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TransIn", Busi+"/TransInConfirm", Busi+"/TransInRevert")
})
dtmcli.FatalIfError(err)
return gid
})
dtmcli.FatalIfError(err)
return gid
}

View File

@ -10,21 +10,6 @@ import (
"github.com/yedf/dtm/dtmcli"
)
// TccBarrierFireRequest 1
func TccBarrierFireRequest() string {
dtmcli.Logf("tcc transaction begin")
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransOutTry", Busi+"/TccBTransOutConfirm", Busi+"/TccBTransOutCancel")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransInTry", Busi+"/TccBTransInConfirm", Busi+"/TccBTransInCancel")
})
dtmcli.FatalIfError(err)
return gid
}
func init() {
setupFuncs["TccBarrierSetup"] = func(app *gin.Engine) {
app.POST(BusiAPI+"/TccBTransInTry", common.WrapHandler(tccBarrierTransInTry))
@ -35,6 +20,19 @@ func init() {
app.POST(BusiAPI+"/TccBTransOutCancel", common.WrapHandler(TccBarrierTransOutCancel))
dtmcli.Logf("examples listening at %d", BusiPort)
}
addSample("tcc_barrier", func() string {
dtmcli.Logf("tcc transaction begin")
gid := dtmcli.MustGenGid(DtmServer)
err := dtmcli.TccGlobalTransaction(DtmServer, gid, func(tcc *dtmcli.Tcc) (*resty.Response, error) {
resp, err := tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransOutTry", Busi+"/TccBTransOutConfirm", Busi+"/TccBTransOutCancel")
if err != nil {
return resp, err
}
return tcc.CallBranch(&TransReq{Amount: 30}, Busi+"/TccBTransInTry", Busi+"/TccBTransInConfirm", Busi+"/TccBTransInCancel")
})
dtmcli.FatalIfError(err)
return gid
})
}
const transInUID = 1

View File

@ -20,18 +20,16 @@ func init() {
})
dtmcli.FatalIfError(err)
}
}
// XaFireRequest 注册全局XA事务调用XA的分支
func XaFireRequest() string {
gid := dtmcli.MustGenGid(DtmServer)
err := XaClient.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) {
resp, err := xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOutXa")
if err != nil {
return resp, err
}
return xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransInXa")
addSample("xa", func() string {
gid := dtmcli.MustGenGid(DtmServer)
err := XaClient.XaGlobalTransaction(gid, func(xa *dtmcli.Xa) (*resty.Response, error) {
resp, err := xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransOutXa")
if err != nil {
return resp, err
}
return xa.CallBranch(&TransReq{Amount: 30}, Busi+"/TransInXa")
})
dtmcli.FatalIfError(err)
return gid
})
dtmcli.FatalIfError(err)
return gid
}

View File

@ -9,15 +9,7 @@ import (
func TestExamples(t *testing.T) {
// for coverage
examples.QsStartSvr()
assertSucceed(t, examples.QsFireRequest())
assertSucceed(t, examples.MsgFireRequest())
assertSucceed(t, examples.SagaBarrierFireRequest())
assertSucceed(t, examples.SagaFireRequest())
assertSucceed(t, examples.SagaWaitFireRequest())
assertSucceed(t, examples.TccBarrierFireRequest())
assertSucceed(t, examples.TccFireRequest())
assertSucceed(t, examples.TccFireRequestNested())
assertSucceed(t, examples.XaFireRequest())
assertSucceed(t, examples.MsgGrpcFireRequest())
assertSucceed(t, examples.GrpcSagaFireRequest())
for _, fn := range examples.Samples {
assertSucceed(t, fn())
}
}