grpc msg may ok

This commit is contained in:
yedf2 2021-08-10 09:54:14 +08:00
parent c19e446455
commit b93af2c16b
19 changed files with 269 additions and 217 deletions

View File

@ -41,6 +41,7 @@ func main() {
// 下面是各类的例子 // 下面是各类的例子
app := examples.BaseAppStartup() app := examples.BaseAppStartup()
examples.GrpcStartup()
if os.Args[1] == "xa" { // 启动xa示例 if os.Args[1] == "xa" { // 启动xa示例
examples.XaSetup(app) examples.XaSetup(app)
examples.XaFireRequest() examples.XaFireRequest()
@ -54,8 +55,8 @@ func main() {
examples.MsgSetup(app) examples.MsgSetup(app)
examples.MsgFireRequest() examples.MsgFireRequest()
} else if os.Args[1] == "msg_pb" { // 启动msg示例 } else if os.Args[1] == "msg_pb" { // 启动msg示例
examples.MsgPbSetup(app) examples.MsgGrpcSetup(app)
examples.MsgPbFireRequest() examples.MsgGrpcFireRequest()
} else if os.Args[1] == "all" { // 运行所有示例 } else if os.Args[1] == "all" { // 运行所有示例
examples.SagaSetup(app) examples.SagaSetup(app)
examples.SagaWaitSetup(app) examples.SagaWaitSetup(app)

View File

@ -2,9 +2,9 @@
// versions: // versions:
// protoc-gen-go v1.26.0 // protoc-gen-go v1.26.0
// protoc v3.17.3 // protoc v3.17.3
// source: dtmpb/dtmpb.proto // source: dtmgrpc/dtmgrpc.proto
package dtmpb package dtmgrpc
import ( import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
@ -36,7 +36,7 @@ type DtmTransInfo struct {
func (x *DtmTransInfo) Reset() { func (x *DtmTransInfo) Reset() {
*x = DtmTransInfo{} *x = DtmTransInfo{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmpb_dtmpb_proto_msgTypes[0] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -49,7 +49,7 @@ func (x *DtmTransInfo) String() string {
func (*DtmTransInfo) ProtoMessage() {} func (*DtmTransInfo) ProtoMessage() {}
func (x *DtmTransInfo) ProtoReflect() protoreflect.Message { func (x *DtmTransInfo) ProtoReflect() protoreflect.Message {
mi := &file_dtmpb_dtmpb_proto_msgTypes[0] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -62,7 +62,7 @@ func (x *DtmTransInfo) ProtoReflect() protoreflect.Message {
// Deprecated: Use DtmTransInfo.ProtoReflect.Descriptor instead. // Deprecated: Use DtmTransInfo.ProtoReflect.Descriptor instead.
func (*DtmTransInfo) Descriptor() ([]byte, []int) { func (*DtmTransInfo) Descriptor() ([]byte, []int) {
return file_dtmpb_dtmpb_proto_rawDescGZIP(), []int{0} return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{0}
} }
func (x *DtmTransInfo) GetGid() string { func (x *DtmTransInfo) GetGid() string {
@ -117,7 +117,7 @@ type DtmRequest struct {
func (x *DtmRequest) Reset() { func (x *DtmRequest) Reset() {
*x = DtmRequest{} *x = DtmRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmpb_dtmpb_proto_msgTypes[1] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -130,7 +130,7 @@ func (x *DtmRequest) String() string {
func (*DtmRequest) ProtoMessage() {} func (*DtmRequest) ProtoMessage() {}
func (x *DtmRequest) ProtoReflect() protoreflect.Message { func (x *DtmRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmpb_dtmpb_proto_msgTypes[1] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -143,7 +143,7 @@ func (x *DtmRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead. // Deprecated: Use DtmRequest.ProtoReflect.Descriptor instead.
func (*DtmRequest) Descriptor() ([]byte, []int) { func (*DtmRequest) Descriptor() ([]byte, []int) {
return file_dtmpb_dtmpb_proto_rawDescGZIP(), []int{1} return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{1}
} }
func (x *DtmRequest) GetGid() string { func (x *DtmRequest) GetGid() string {
@ -201,7 +201,7 @@ type DtmReply struct {
func (x *DtmReply) Reset() { func (x *DtmReply) Reset() {
*x = DtmReply{} *x = DtmReply{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmpb_dtmpb_proto_msgTypes[2] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -214,7 +214,7 @@ func (x *DtmReply) String() string {
func (*DtmReply) ProtoMessage() {} func (*DtmReply) ProtoMessage() {}
func (x *DtmReply) ProtoReflect() protoreflect.Message { func (x *DtmReply) ProtoReflect() protoreflect.Message {
mi := &file_dtmpb_dtmpb_proto_msgTypes[2] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -227,7 +227,7 @@ func (x *DtmReply) ProtoReflect() protoreflect.Message {
// Deprecated: Use DtmReply.ProtoReflect.Descriptor instead. // Deprecated: Use DtmReply.ProtoReflect.Descriptor instead.
func (*DtmReply) Descriptor() ([]byte, []int) { func (*DtmReply) Descriptor() ([]byte, []int) {
return file_dtmpb_dtmpb_proto_rawDescGZIP(), []int{2} return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{2}
} }
func (x *DtmReply) GetDtmResult() string { func (x *DtmReply) GetDtmResult() string {
@ -258,7 +258,7 @@ type BusiRequest struct {
func (x *BusiRequest) Reset() { func (x *BusiRequest) Reset() {
*x = BusiRequest{} *x = BusiRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmpb_dtmpb_proto_msgTypes[3] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -271,7 +271,7 @@ func (x *BusiRequest) String() string {
func (*BusiRequest) ProtoMessage() {} func (*BusiRequest) ProtoMessage() {}
func (x *BusiRequest) ProtoReflect() protoreflect.Message { func (x *BusiRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmpb_dtmpb_proto_msgTypes[3] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -284,7 +284,7 @@ func (x *BusiRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use BusiRequest.ProtoReflect.Descriptor instead. // Deprecated: Use BusiRequest.ProtoReflect.Descriptor instead.
func (*BusiRequest) Descriptor() ([]byte, []int) { func (*BusiRequest) Descriptor() ([]byte, []int) {
return file_dtmpb_dtmpb_proto_rawDescGZIP(), []int{3} return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{3}
} }
func (x *BusiRequest) GetInfo() *DtmTransInfo { func (x *BusiRequest) GetInfo() *DtmTransInfo {
@ -321,7 +321,7 @@ type BusiReply struct {
func (x *BusiReply) Reset() { func (x *BusiReply) Reset() {
*x = BusiReply{} *x = BusiReply{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmpb_dtmpb_proto_msgTypes[4] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -334,7 +334,7 @@ func (x *BusiReply) String() string {
func (*BusiReply) ProtoMessage() {} func (*BusiReply) ProtoMessage() {}
func (x *BusiReply) ProtoReflect() protoreflect.Message { func (x *BusiReply) ProtoReflect() protoreflect.Message {
mi := &file_dtmpb_dtmpb_proto_msgTypes[4] mi := &file_dtmgrpc_dtmgrpc_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -347,7 +347,7 @@ func (x *BusiReply) ProtoReflect() protoreflect.Message {
// Deprecated: Use BusiReply.ProtoReflect.Descriptor instead. // Deprecated: Use BusiReply.ProtoReflect.Descriptor instead.
func (*BusiReply) Descriptor() ([]byte, []int) { func (*BusiReply) Descriptor() ([]byte, []int) {
return file_dtmpb_dtmpb_proto_rawDescGZIP(), []int{4} return file_dtmgrpc_dtmgrpc_proto_rawDescGZIP(), []int{4}
} }
func (x *BusiReply) GetDtmResult() string { func (x *BusiReply) GetDtmResult() string {
@ -364,97 +364,98 @@ func (x *BusiReply) GetDtmMessage() string {
return "" return ""
} }
var File_dtmpb_dtmpb_proto protoreflect.FileDescriptor var File_dtmgrpc_dtmgrpc_proto protoreflect.FileDescriptor
var file_dtmpb_dtmpb_proto_rawDesc = []byte{ var file_dtmgrpc_dtmgrpc_proto_rawDesc = []byte{
0x0a, 0x11, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x2f, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x2e, 0x70, 0x72, 0x0a, 0x15, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70,
0x6f, 0x74, 0x6f, 0x12, 0x05, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63,
0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x01, 0x0a, 0x0c, 0x44, 0x74, 0x6d, 0x54, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x01,
0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x0a, 0x0c, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64,
0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20,
0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a,
0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x0a, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
0x63, 0x68, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x52, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x42, 0x72,
0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x44, 0x74,
0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x22, 0x84, 0x02, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x22, 0x86, 0x02, 0x0a,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47,
0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a,
0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x51,
0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01,
0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65,
0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18,
0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x32, 0x0a, 0x05, 0x45, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x57, 0x61, 0x69, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x78, 0x74, 0x72, 0x61, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x64, 0x74, 0x6d, 0x74, 0x12, 0x34, 0x0a, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b,
0x70, 0x62, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x32, 0x1e, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65,
0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79,
0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x52, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18,
0x61, 0x74, 0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45,
0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x48, 0x0a, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x08, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x48, 0x0a, 0x08, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c,
0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01,
0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12,
0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x44, 0x74, 0x6d, 0x1e, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xbf, 0x01, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x27, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0xc3, 0x01, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x2e, 0x44, 0x74, 0x29, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e,
0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73,
0x12, 0x33, 0x0a, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x35, 0x0a, 0x05, 0x45, 0x78,
0x1d, 0x2e, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x74, 0x72, 0x61, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x64, 0x74, 0x6d, 0x67,
0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x72, 0x70, 0x63, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e,
0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x45, 0x78, 0x74, 0x72,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01,
0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x28, 0x0c, 0x52, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45,
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x49, 0x0a, 0x09, 0x42, 0x75, 0x73, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x49, 0x0a, 0x09, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70,
0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x6c, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18,
0x73, 0x75, 0x6c, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74,
0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02,
0x73, 0x61, 0x67, 0x65, 0x32, 0x3c, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x35, 0x0a, 0x06, 0x53, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x75, 0x62, 0x6d, 0x69, 0x74, 0x12, 0x11, 0x2e, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x2e, 0x44, 0x74, 0x32, 0x3e, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x37, 0x0a, 0x06, 0x53, 0x75, 0x62, 0x6d, 0x69,
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x44, 0x74, 0x6d, 0x52,
0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
0x22, 0x00, 0x42, 0x1b, 0x5a, 0x19, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00,
0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x70, 0x62, 0x62, 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, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
file_dtmpb_dtmpb_proto_rawDescOnce sync.Once file_dtmgrpc_dtmgrpc_proto_rawDescOnce sync.Once
file_dtmpb_dtmpb_proto_rawDescData = file_dtmpb_dtmpb_proto_rawDesc file_dtmgrpc_dtmgrpc_proto_rawDescData = file_dtmgrpc_dtmgrpc_proto_rawDesc
) )
func file_dtmpb_dtmpb_proto_rawDescGZIP() []byte { func file_dtmgrpc_dtmgrpc_proto_rawDescGZIP() []byte {
file_dtmpb_dtmpb_proto_rawDescOnce.Do(func() { file_dtmgrpc_dtmgrpc_proto_rawDescOnce.Do(func() {
file_dtmpb_dtmpb_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmpb_dtmpb_proto_rawDescData) file_dtmgrpc_dtmgrpc_proto_rawDescData = protoimpl.X.CompressGZIP(file_dtmgrpc_dtmgrpc_proto_rawDescData)
}) })
return file_dtmpb_dtmpb_proto_rawDescData return file_dtmgrpc_dtmgrpc_proto_rawDescData
} }
var file_dtmpb_dtmpb_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_dtmgrpc_dtmgrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_dtmpb_dtmpb_proto_goTypes = []interface{}{ var file_dtmgrpc_dtmgrpc_proto_goTypes = []interface{}{
(*DtmTransInfo)(nil), // 0: dtmpb.DtmTransInfo (*DtmTransInfo)(nil), // 0: dtmgrpc.DtmTransInfo
(*DtmRequest)(nil), // 1: dtmpb.DtmRequest (*DtmRequest)(nil), // 1: dtmgrpc.DtmRequest
(*DtmReply)(nil), // 2: dtmpb.DtmReply (*DtmReply)(nil), // 2: dtmgrpc.DtmReply
(*BusiRequest)(nil), // 3: dtmpb.BusiRequest (*BusiRequest)(nil), // 3: dtmgrpc.BusiRequest
(*BusiReply)(nil), // 4: dtmpb.BusiReply (*BusiReply)(nil), // 4: dtmgrpc.BusiReply
nil, // 5: dtmpb.DtmRequest.ExtraEntry nil, // 5: dtmgrpc.DtmRequest.ExtraEntry
nil, // 6: dtmpb.BusiRequest.ExtraEntry nil, // 6: dtmgrpc.BusiRequest.ExtraEntry
(*emptypb.Empty)(nil), // 7: google.protobuf.Empty (*emptypb.Empty)(nil), // 7: google.protobuf.Empty
} }
var file_dtmpb_dtmpb_proto_depIdxs = []int32{ var file_dtmgrpc_dtmgrpc_proto_depIdxs = []int32{
5, // 0: dtmpb.DtmRequest.Extra:type_name -> dtmpb.DtmRequest.ExtraEntry 5, // 0: dtmgrpc.DtmRequest.Extra:type_name -> dtmgrpc.DtmRequest.ExtraEntry
0, // 1: dtmpb.BusiRequest.info:type_name -> dtmpb.DtmTransInfo 0, // 1: dtmgrpc.BusiRequest.info:type_name -> dtmgrpc.DtmTransInfo
6, // 2: dtmpb.BusiRequest.Extra:type_name -> dtmpb.BusiRequest.ExtraEntry 6, // 2: dtmgrpc.BusiRequest.Extra:type_name -> dtmgrpc.BusiRequest.ExtraEntry
1, // 3: dtmpb.Dtm.Submit:input_type -> dtmpb.DtmRequest 1, // 3: dtmgrpc.Dtm.Submit:input_type -> dtmgrpc.DtmRequest
7, // 4: dtmpb.Dtm.Submit:output_type -> google.protobuf.Empty 7, // 4: dtmgrpc.Dtm.Submit:output_type -> google.protobuf.Empty
4, // [4:5] is the sub-list for method output_type 4, // [4:5] is the sub-list for method output_type
3, // [3:4] is the sub-list for method input_type 3, // [3:4] 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 type_name
@ -462,13 +463,13 @@ var file_dtmpb_dtmpb_proto_depIdxs = []int32{
0, // [0:3] is the sub-list for field type_name 0, // [0:3] is the sub-list for field type_name
} }
func init() { file_dtmpb_dtmpb_proto_init() } func init() { file_dtmgrpc_dtmgrpc_proto_init() }
func file_dtmpb_dtmpb_proto_init() { func file_dtmgrpc_dtmgrpc_proto_init() {
if File_dtmpb_dtmpb_proto != nil { if File_dtmgrpc_dtmgrpc_proto != nil {
return return
} }
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_dtmpb_dtmpb_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { file_dtmgrpc_dtmgrpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmTransInfo); i { switch v := v.(*DtmTransInfo); i {
case 0: case 0:
return &v.state return &v.state
@ -480,7 +481,7 @@ func file_dtmpb_dtmpb_proto_init() {
return nil return nil
} }
} }
file_dtmpb_dtmpb_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { file_dtmgrpc_dtmgrpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmRequest); i { switch v := v.(*DtmRequest); i {
case 0: case 0:
return &v.state return &v.state
@ -492,7 +493,7 @@ func file_dtmpb_dtmpb_proto_init() {
return nil return nil
} }
} }
file_dtmpb_dtmpb_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { file_dtmgrpc_dtmgrpc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmReply); i { switch v := v.(*DtmReply); i {
case 0: case 0:
return &v.state return &v.state
@ -504,7 +505,7 @@ func file_dtmpb_dtmpb_proto_init() {
return nil return nil
} }
} }
file_dtmpb_dtmpb_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { file_dtmgrpc_dtmgrpc_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiRequest); i { switch v := v.(*BusiRequest); i {
case 0: case 0:
return &v.state return &v.state
@ -516,7 +517,7 @@ func file_dtmpb_dtmpb_proto_init() {
return nil return nil
} }
} }
file_dtmpb_dtmpb_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { file_dtmgrpc_dtmgrpc_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiReply); i { switch v := v.(*BusiReply); i {
case 0: case 0:
return &v.state return &v.state
@ -533,18 +534,18 @@ func file_dtmpb_dtmpb_proto_init() {
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_dtmpb_dtmpb_proto_rawDesc, RawDescriptor: file_dtmgrpc_dtmgrpc_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 7, NumMessages: 7,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },
GoTypes: file_dtmpb_dtmpb_proto_goTypes, GoTypes: file_dtmgrpc_dtmgrpc_proto_goTypes,
DependencyIndexes: file_dtmpb_dtmpb_proto_depIdxs, DependencyIndexes: file_dtmgrpc_dtmgrpc_proto_depIdxs,
MessageInfos: file_dtmpb_dtmpb_proto_msgTypes, MessageInfos: file_dtmgrpc_dtmgrpc_proto_msgTypes,
}.Build() }.Build()
File_dtmpb_dtmpb_proto = out.File File_dtmgrpc_dtmgrpc_proto = out.File
file_dtmpb_dtmpb_proto_rawDesc = nil file_dtmgrpc_dtmgrpc_proto_rawDesc = nil
file_dtmpb_dtmpb_proto_goTypes = nil file_dtmgrpc_dtmgrpc_proto_goTypes = nil
file_dtmpb_dtmpb_proto_depIdxs = nil file_dtmgrpc_dtmgrpc_proto_depIdxs = nil
} }

View File

@ -1,9 +1,9 @@
syntax = "proto3"; syntax = "proto3";
option go_package = "github.com/yedf/dtm/dtmpb"; option go_package = "github.com/yedf/dtm/dtmgrpc";
import "google/protobuf/empty.proto"; import "google/protobuf/empty.proto";
package dtmpb; package dtmgrpc;
// The dtm service definition. // The dtm service definition.
service Dtm { service Dtm {

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT. // Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package dtmpb package dtmgrpc
import ( import (
context "context" context "context"
@ -32,7 +32,7 @@ func NewDtmClient(cc grpc.ClientConnInterface) DtmClient {
func (c *dtmClient) Submit(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { func (c *dtmClient) Submit(ctx context.Context, in *DtmRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty) out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/dtmpb.Dtm/Submit", in, out, opts...) err := c.cc.Invoke(ctx, "/dtmgrpc.Dtm/Submit", in, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,7 +77,7 @@ func _Dtm_Submit_Handler(srv interface{}, ctx context.Context, dec func(interfac
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: "/dtmpb.Dtm/Submit", FullMethod: "/dtmgrpc.Dtm/Submit",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DtmServer).Submit(ctx, req.(*DtmRequest)) return srv.(DtmServer).Submit(ctx, req.(*DtmRequest))
@ -89,7 +89,7 @@ func _Dtm_Submit_Handler(srv interface{}, ctx context.Context, dec func(interfac
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
var Dtm_ServiceDesc = grpc.ServiceDesc{ var Dtm_ServiceDesc = grpc.ServiceDesc{
ServiceName: "dtmpb.Dtm", ServiceName: "dtmgrpc.Dtm",
HandlerType: (*DtmServer)(nil), HandlerType: (*DtmServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
@ -98,5 +98,5 @@ var Dtm_ServiceDesc = grpc.ServiceDesc{
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "dtmpb/dtmpb.proto", Metadata: "dtmgrpc/dtmgrpc.proto",
} }

View File

@ -1,4 +1,4 @@
package dtmpb package dtmgrpc
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package dtmpb package dtmgrpc
import ( import (
context "context" context "context"

View File

@ -3,7 +3,7 @@ package dtmsvr
import ( import (
"context" "context"
pb "github.com/yedf/dtm/dtmpb" pb "github.com/yedf/dtm/dtmgrpc"
"google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/emptypb"
) )

View File

@ -47,6 +47,7 @@ func TestMain(m *testing.M) {
// 启动组件 // 启动组件
go StartSvr() go StartSvr()
app = examples.BaseAppStartup() app = examples.BaseAppStartup()
examples.GrpcStartup()
examples.SagaSetup(app) examples.SagaSetup(app)
examples.TccSetup(app) examples.TccSetup(app)
examples.XaSetup(app) examples.XaSetup(app)

View File

@ -18,5 +18,5 @@ func TestExamples(t *testing.T) {
assertSucceed(t, examples.TccFireRequest()) assertSucceed(t, examples.TccFireRequest())
assertSucceed(t, examples.TccFireRequestNested()) assertSucceed(t, examples.TccFireRequestNested())
assertSucceed(t, examples.XaFireRequest()) assertSucceed(t, examples.XaFireRequest())
assertSucceed(t, examples.MsgPbFireRequest()) assertSucceed(t, examples.MsgGrpcFireRequest())
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/yedf/dtm/common" "github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmpb" "github.com/yedf/dtm/dtmgrpc"
"github.com/yedf/dtm/examples" "github.com/yedf/dtm/examples"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -26,8 +26,8 @@ func StartSvr() {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", dtmsvrGrpcPort)) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", dtmsvrGrpcPort))
dtmcli.FatalIfError(err) dtmcli.FatalIfError(err)
s := grpc.NewServer(grpc.UnaryInterceptor(dtmpb.GrpcServerLog)) s := grpc.NewServer(grpc.UnaryInterceptor(dtmgrpc.GrpcServerLog))
dtmpb.RegisterDtmServer(s, &dtmServer{}) dtmgrpc.RegisterDtmServer(s, &dtmServer{})
dtmcli.Logf("grpc listening at %v", lis.Addr()) dtmcli.Logf("grpc listening at %v", lis.Addr())
go func() { go func() {
err := s.Serve(lis) err := s.Serve(lis)

View File

@ -9,7 +9,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/yedf/dtm/common" "github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmpb" "github.com/yedf/dtm/dtmgrpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/emptypb"
@ -160,10 +160,10 @@ func (t *TransGlobal) setNextCron(expireIn int64) []string {
func (t *TransGlobal) getBranchResult(branch *TransBranch) string { func (t *TransGlobal) getBranchResult(branch *TransBranch) string {
if t.Protocol == "grpc" { if t.Protocol == "grpc" {
server, method := dtmpb.GetServerAndMethod(branch.URL) server, method := dtmgrpc.GetServerAndMethod(branch.URL)
conn := dtmpb.MustGetGrpcConn(server) conn := dtmgrpc.MustGetGrpcConn(server)
err := conn.Invoke(context.Background(), method, &dtmpb.BusiRequest{ err := conn.Invoke(context.Background(), method, &dtmgrpc.BusiRequest{
Info: &dtmpb.DtmTransInfo{ Info: &dtmgrpc.DtmTransInfo{
Gid: t.Gid, Gid: t.Gid,
TransType: t.TransType, TransType: t.TransType,
BranchID: branch.BranchID, BranchID: branch.BranchID,
@ -245,7 +245,7 @@ func TransFromContext(c *gin.Context) *TransGlobal {
} }
// TransFromDtmRequest TransFromContext // TransFromDtmRequest TransFromContext
func TransFromDtmRequest(c *dtmpb.DtmRequest) *TransGlobal { func TransFromDtmRequest(c *dtmgrpc.DtmRequest) *TransGlobal {
return &TransGlobal{ return &TransGlobal{
Gid: c.Gid, Gid: c.Gid,
TransType: c.TransType, TransType: c.TransType,

View File

@ -0,0 +1,43 @@
package dtmsvr
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/yedf/dtm/dtmcli"
"github.com/yedf/dtm/dtmgrpc"
"github.com/yedf/dtm/examples"
)
func TestGrpcMsg(t *testing.T) {
grpcMsgNormal(t)
grpcMsgPending(t)
}
func grpcMsgNormal(t *testing.T) {
msg := genGrpcMsg("grpc-msg-normal")
err := msg.Submit()
assert.Nil(t, err)
WaitTransProcessed(msg.Gid)
assert.Equal(t, "succeed", getTransStatus(msg.Gid))
}
func grpcMsgPending(t *testing.T) {
msg := genGrpcMsg("grpc-msg-pending")
examples.MainSwitch.TransInResult.SetOnce("PENDING")
err := msg.Submit()
assert.Nil(t, err)
WaitTransProcessed(msg.Gid)
assert.Equal(t, "submitted", getTransStatus(msg.Gid))
CronTransOnce(60 * time.Second)
assert.Equal(t, "succeed", getTransStatus(msg.Gid))
}
func genGrpcMsg(gid string) *dtmgrpc.MsgGrpc {
req := dtmcli.MustMarshal(&examples.TransReq{Amount: 30})
return dtmgrpc.NewMsgGrpc(examples.DtmGrpcServer, gid).
Add(examples.BusiPb+"/examples.Busi/TransOut", req).
Add(examples.BusiPb+"/examples.Busi/TransIn", req)
}

View File

@ -1,8 +0,0 @@
package dtmsvr
import (
"testing"
)
func TestPbMsg(t *testing.T) {
}

View File

@ -7,7 +7,7 @@
package examples package examples
import ( import (
dtmpb "github.com/yedf/dtm/dtmpb" dtmgrpc "github.com/yedf/dtm/dtmgrpc"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb" emptypb "google.golang.org/protobuf/types/known/emptypb"
@ -51,14 +51,14 @@ var file_examples_busi_proto_rawDesc = []byte{
} }
var file_examples_busi_proto_goTypes = []interface{}{ var file_examples_busi_proto_goTypes = []interface{}{
(*dtmpb.BusiRequest)(nil), // 0: dtmpb.BusiRequest (*dtmgrpc.BusiRequest)(nil), // 0: dtmgrpc.BusiRequest
(*emptypb.Empty)(nil), // 1: google.protobuf.Empty (*emptypb.Empty)(nil), // 1: google.protobuf.Empty
} }
var file_examples_busi_proto_depIdxs = []int32{ var file_examples_busi_proto_depIdxs = []int32{
0, // 0: examples.Busi.TransIn:input_type -> dtmpb.BusiRequest 0, // 0: examples.Busi.TransIn:input_type -> dtmgrpc.BusiRequest
0, // 1: examples.Busi.TransOut:input_type -> dtmpb.BusiRequest 0, // 1: examples.Busi.TransOut:input_type -> dtmgrpc.BusiRequest
0, // 2: examples.Busi.TransInRevert:input_type -> dtmpb.BusiRequest 0, // 2: examples.Busi.TransInRevert:input_type -> dtmgrpc.BusiRequest
0, // 3: examples.Busi.TransOutRevert:input_type -> dtmpb.BusiRequest 0, // 3: examples.Busi.TransOutRevert:input_type -> dtmgrpc.BusiRequest
1, // 4: examples.Busi.TransIn:output_type -> google.protobuf.Empty 1, // 4: examples.Busi.TransIn:output_type -> google.protobuf.Empty
1, // 5: examples.Busi.TransOut:output_type -> google.protobuf.Empty 1, // 5: examples.Busi.TransOut:output_type -> google.protobuf.Empty
1, // 6: examples.Busi.TransInRevert:output_type -> google.protobuf.Empty 1, // 6: examples.Busi.TransInRevert:output_type -> google.protobuf.Empty

View File

@ -3,14 +3,14 @@ syntax = "proto3";
package examples; package examples;
option go_package = "github.com/yedf/dtm/examples"; option go_package = "github.com/yedf/dtm/examples";
import "dtmpb/dtmpb.proto"; import "dtmgrpc/dtmgrpc.proto";
import "google/protobuf/empty.proto"; import "google/protobuf/empty.proto";
// The dtm service definition. // The dtm service definition.
service Busi { service Busi {
rpc TransIn(dtmpb.BusiRequest) returns (google.protobuf.Empty) {} rpc TransIn(dtmgrpc.BusiRequest) returns (google.protobuf.Empty) {}
rpc TransOut(dtmpb.BusiRequest) returns (google.protobuf.Empty) {} rpc TransOut(dtmgrpc.BusiRequest) returns (google.protobuf.Empty) {}
rpc TransInRevert(dtmpb.BusiRequest) returns (google.protobuf.Empty) {} rpc TransInRevert(dtmgrpc.BusiRequest) returns (google.protobuf.Empty) {}
rpc TransOutRevert(dtmpb.BusiRequest) returns (google.protobuf.Empty) {} rpc TransOutRevert(dtmgrpc.BusiRequest) returns (google.protobuf.Empty) {}
} }

View File

@ -4,7 +4,7 @@ package examples
import ( import (
context "context" context "context"
dtmpb "github.com/yedf/dtm/dtmpb" dtmgrpc "github.com/yedf/dtm/dtmgrpc"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
@ -20,10 +20,10 @@ 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. // 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 BusiClient interface { type BusiClient interface {
TransIn(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) TransIn(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
TransOut(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) TransOut(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
TransInRevert(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) TransInRevert(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
TransOutRevert(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) TransOutRevert(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
} }
type busiClient struct { type busiClient struct {
@ -34,7 +34,7 @@ func NewBusiClient(cc grpc.ClientConnInterface) BusiClient {
return &busiClient{cc} return &busiClient{cc}
} }
func (c *busiClient) TransIn(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { func (c *busiClient) TransIn(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty) out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/examples.Busi/TransIn", in, out, opts...) err := c.cc.Invoke(ctx, "/examples.Busi/TransIn", in, out, opts...)
if err != nil { if err != nil {
@ -43,7 +43,7 @@ func (c *busiClient) TransIn(ctx context.Context, in *dtmpb.BusiRequest, opts ..
return out, nil return out, nil
} }
func (c *busiClient) TransOut(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { func (c *busiClient) TransOut(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty) out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/examples.Busi/TransOut", in, out, opts...) err := c.cc.Invoke(ctx, "/examples.Busi/TransOut", in, out, opts...)
if err != nil { if err != nil {
@ -52,7 +52,7 @@ func (c *busiClient) TransOut(ctx context.Context, in *dtmpb.BusiRequest, opts .
return out, nil return out, nil
} }
func (c *busiClient) TransInRevert(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { func (c *busiClient) TransInRevert(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty) out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/examples.Busi/TransInRevert", in, out, opts...) err := c.cc.Invoke(ctx, "/examples.Busi/TransInRevert", in, out, opts...)
if err != nil { if err != nil {
@ -61,7 +61,7 @@ func (c *busiClient) TransInRevert(ctx context.Context, in *dtmpb.BusiRequest, o
return out, nil return out, nil
} }
func (c *busiClient) TransOutRevert(ctx context.Context, in *dtmpb.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { func (c *busiClient) TransOutRevert(ctx context.Context, in *dtmgrpc.BusiRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty) out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/examples.Busi/TransOutRevert", in, out, opts...) err := c.cc.Invoke(ctx, "/examples.Busi/TransOutRevert", in, out, opts...)
if err != nil { if err != nil {
@ -74,10 +74,10 @@ func (c *busiClient) TransOutRevert(ctx context.Context, in *dtmpb.BusiRequest,
// All implementations must embed UnimplementedBusiServer // All implementations must embed UnimplementedBusiServer
// for forward compatibility // for forward compatibility
type BusiServer interface { type BusiServer interface {
TransIn(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) TransIn(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error)
TransOut(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) TransOut(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error)
TransInRevert(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) TransInRevert(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error)
TransOutRevert(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) TransOutRevert(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedBusiServer() mustEmbedUnimplementedBusiServer()
} }
@ -85,16 +85,16 @@ type BusiServer interface {
type UnimplementedBusiServer struct { type UnimplementedBusiServer struct {
} }
func (UnimplementedBusiServer) TransIn(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (UnimplementedBusiServer) TransIn(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method TransIn not implemented") return nil, status.Errorf(codes.Unimplemented, "method TransIn not implemented")
} }
func (UnimplementedBusiServer) TransOut(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (UnimplementedBusiServer) TransOut(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method TransOut not implemented") return nil, status.Errorf(codes.Unimplemented, "method TransOut not implemented")
} }
func (UnimplementedBusiServer) TransInRevert(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (UnimplementedBusiServer) TransInRevert(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method TransInRevert not implemented") return nil, status.Errorf(codes.Unimplemented, "method TransInRevert not implemented")
} }
func (UnimplementedBusiServer) TransOutRevert(context.Context, *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (UnimplementedBusiServer) TransOutRevert(context.Context, *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method TransOutRevert not implemented") return nil, status.Errorf(codes.Unimplemented, "method TransOutRevert not implemented")
} }
func (UnimplementedBusiServer) mustEmbedUnimplementedBusiServer() {} func (UnimplementedBusiServer) mustEmbedUnimplementedBusiServer() {}
@ -111,7 +111,7 @@ func RegisterBusiServer(s grpc.ServiceRegistrar, srv BusiServer) {
} }
func _Busi_TransIn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _Busi_TransIn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(dtmpb.BusiRequest) in := new(dtmgrpc.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -123,13 +123,13 @@ func _Busi_TransIn_Handler(srv interface{}, ctx context.Context, dec func(interf
FullMethod: "/examples.Busi/TransIn", FullMethod: "/examples.Busi/TransIn",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BusiServer).TransIn(ctx, req.(*dtmpb.BusiRequest)) return srv.(BusiServer).TransIn(ctx, req.(*dtmgrpc.BusiRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Busi_TransOut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _Busi_TransOut_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(dtmpb.BusiRequest) in := new(dtmgrpc.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -141,13 +141,13 @@ func _Busi_TransOut_Handler(srv interface{}, ctx context.Context, dec func(inter
FullMethod: "/examples.Busi/TransOut", FullMethod: "/examples.Busi/TransOut",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BusiServer).TransOut(ctx, req.(*dtmpb.BusiRequest)) return srv.(BusiServer).TransOut(ctx, req.(*dtmgrpc.BusiRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Busi_TransInRevert_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _Busi_TransInRevert_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(dtmpb.BusiRequest) in := new(dtmgrpc.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -159,13 +159,13 @@ func _Busi_TransInRevert_Handler(srv interface{}, ctx context.Context, dec func(
FullMethod: "/examples.Busi/TransInRevert", FullMethod: "/examples.Busi/TransInRevert",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BusiServer).TransInRevert(ctx, req.(*dtmpb.BusiRequest)) return srv.(BusiServer).TransInRevert(ctx, req.(*dtmgrpc.BusiRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Busi_TransOutRevert_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _Busi_TransOutRevert_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(dtmpb.BusiRequest) in := new(dtmgrpc.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -177,7 +177,7 @@ func _Busi_TransOutRevert_Handler(srv interface{}, ctx context.Context, dec func
FullMethod: "/examples.Busi/TransOutRevert", FullMethod: "/examples.Busi/TransOutRevert",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BusiServer).TransOutRevert(ctx, req.(*dtmpb.BusiRequest)) return srv.(BusiServer).TransOutRevert(ctx, req.(*dtmgrpc.BusiRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }

View File

@ -2,14 +2,11 @@ package examples
import ( import (
"fmt" "fmt"
"net"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/yedf/dtm/common" "github.com/yedf/dtm/common"
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
dtmpb "github.com/yedf/dtm/dtmpb"
grpc "google.golang.org/grpc"
) )
const ( const (
@ -24,12 +21,6 @@ const (
// Busi busi service url prefix // Busi busi service url prefix
var Busi string = fmt.Sprintf("http://localhost:%d%s", BusiPort, BusiAPI) var Busi string = fmt.Sprintf("http://localhost:%d%s", BusiPort, BusiAPI)
// BusiPb busi service grpc address
var BusiPb string = fmt.Sprintf("localhost:%d", BusiPbPort)
// DtmClient grpc client for dtm
var DtmClient dtmpb.DtmClient = nil
// BaseAppStartup base app startup // BaseAppStartup base app startup
func BaseAppStartup() *gin.Engine { func BaseAppStartup() *gin.Engine {
dtmcli.Logf("examples starting") dtmcli.Logf("examples starting")
@ -38,21 +29,6 @@ func BaseAppStartup() *gin.Engine {
dtmcli.Logf("Starting busi at: %d", BusiPort) dtmcli.Logf("Starting busi at: %d", BusiPort)
go app.Run(fmt.Sprintf(":%d", BusiPort)) go app.Run(fmt.Sprintf(":%d", BusiPort))
conn, err := grpc.Dial(DtmGrpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(dtmpb.GrpcClientLog))
dtmcli.FatalIfError(err)
DtmClient = dtmpb.NewDtmClient(conn)
dtmcli.Logf("dtm client inited")
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", BusiPbPort))
dtmcli.FatalIfError(err)
s := grpc.NewServer(grpc.UnaryInterceptor(dtmpb.GrpcServerLog))
RegisterBusiServer(s, &busiServer{})
dtmcli.Logf("busi grpc listening at %v", lis.Addr())
go func() {
err := s.Serve(lis)
dtmcli.FatalIfError(err)
}()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
return app return app
} }
@ -92,7 +68,6 @@ func handleGeneralBusiness(c *gin.Context, result1 string, result2 string, busi
res := dtmcli.OrString(result1, result2, "SUCCESS") res := dtmcli.OrString(result1, result2, "SUCCESS")
dtmcli.Logf("%s %s result: %s", busi, info.String(), res) dtmcli.Logf("%s %s result: %s", busi, info.String(), res)
return M{"dtm_result": res}, nil return M{"dtm_result": res}, nil
} }
// BaseAddRoute add base route handler // BaseAddRoute add base route handler

View File

@ -2,27 +2,66 @@ package examples
import ( import (
"context" "context"
"fmt"
"net"
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
dtmpb "github.com/yedf/dtm/dtmpb" dtmgrpc "github.com/yedf/dtm/dtmgrpc"
grpc "google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/emptypb"
) )
// BusiPb busi service grpc address
var BusiPb string = fmt.Sprintf("localhost:%d", BusiPbPort)
// DtmClient grpc client for dtm
var DtmClient dtmgrpc.DtmClient = nil
// GrpcStartup for grpc
func GrpcStartup() {
conn, err := grpc.Dial(DtmGrpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(dtmgrpc.GrpcClientLog))
dtmcli.FatalIfError(err)
DtmClient = dtmgrpc.NewDtmClient(conn)
dtmcli.Logf("dtm client inited")
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", BusiPbPort))
dtmcli.FatalIfError(err)
s := grpc.NewServer(grpc.UnaryInterceptor(dtmgrpc.GrpcServerLog))
RegisterBusiServer(s, &busiServer{})
dtmcli.Logf("busi grpc listening at %v", lis.Addr())
go func() {
err := s.Serve(lis)
dtmcli.FatalIfError(err)
}()
}
func handleGrpcBusiness(in *dtmgrpc.BusiRequest, result1 string, result2 string, busi string) error {
res := dtmcli.OrString(result1, result2, "SUCCESS")
dtmcli.Logf("grpc busi %s %s result: %s", busi, in.Info, res)
if res == "SUCCESS" {
return nil
} else if res == "FAILURE" {
return status.New(codes.Aborted, "user want to rollback").Err()
}
return status.New(codes.Internal, fmt.Sprintf("unknow result %s", res)).Err()
}
// busiServer is used to implement helloworld.GreeterServer. // busiServer is used to implement helloworld.GreeterServer.
type busiServer struct { type busiServer struct {
UnimplementedBusiServer UnimplementedBusiServer
} }
func (s *busiServer) TransIn(ctx context.Context, in *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (s *busiServer) TransIn(ctx context.Context, in *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
req := TransReq{} req := TransReq{}
dtmcli.MustUnmarshal(in.AppData, &req) dtmcli.MustUnmarshal(in.AppData, &req)
dtmcli.Logf("busiServer %s received: %v %v", dtmcli.GetFuncName(), in.Info, req) return &emptypb.Empty{}, handleGrpcBusiness(in, req.TransInResult, MainSwitch.TransInResult.Fetch(), "TransIn")
return &emptypb.Empty{}, nil
} }
func (s *busiServer) TransOut(ctx context.Context, in *dtmpb.BusiRequest) (*emptypb.Empty, error) { func (s *busiServer) TransOut(ctx context.Context, in *dtmgrpc.BusiRequest) (*emptypb.Empty, error) {
req := TransReq{} req := TransReq{}
dtmcli.MustUnmarshal(in.AppData, &req) dtmcli.MustUnmarshal(in.AppData, &req)
dtmcli.Logf("busiServer %s received: %v %v", dtmcli.GetFuncName(), in.Info, req) return &emptypb.Empty{}, handleGrpcBusiness(in, req.TransOutResult, MainSwitch.TransOutResult.Fetch(), "TransOut")
return &emptypb.Empty{}, nil
} }

View File

@ -3,18 +3,18 @@ package examples
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/yedf/dtm/dtmcli" "github.com/yedf/dtm/dtmcli"
dtmpb "github.com/yedf/dtm/dtmpb" dtmgrpc "github.com/yedf/dtm/dtmgrpc"
) )
// MsgPbSetup 1 // MsgGrpcSetup 1
func MsgPbSetup(app *gin.Engine) { func MsgGrpcSetup(app *gin.Engine) {
} }
// MsgPbFireRequest 1 // MsgGrpcFireRequest 1
func MsgPbFireRequest() string { func MsgGrpcFireRequest() string {
req := dtmcli.MustMarshal(&TransReq{Amount: 30}) req := dtmcli.MustMarshal(&TransReq{Amount: 30})
msg := dtmpb.NewMsgGrpc(DtmGrpcServer, dtmcli.MustGenGid(DtmServer)). msg := dtmgrpc.NewMsgGrpc(DtmGrpcServer, dtmcli.MustGenGid(DtmServer)).
Add(BusiPb+"/examples.Busi/TransOut", req). Add(BusiPb+"/examples.Busi/TransOut", req).
Add(BusiPb+"/examples.Busi/TransIn", req) Add(BusiPb+"/examples.Busi/TransIn", req)
err := msg.Submit() err := msg.Submit()