grpc msg sent

This commit is contained in:
yedf2 2021-08-09 13:38:47 +08:00
parent e7c89523c2
commit 436b1c7be0
7 changed files with 188 additions and 57 deletions

View File

@ -53,6 +53,9 @@ func main() {
} else if os.Args[1] == "msg" { // 启动msg示例 } else if os.Args[1] == "msg" { // 启动msg示例
examples.MsgSetup(app) examples.MsgSetup(app)
examples.MsgFireRequest() examples.MsgFireRequest()
} else if os.Args[1] == "msg_pb" { // 启动msg示例
examples.MsgPbSetup(app)
examples.MsgPbFireRequest()
} 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

@ -20,6 +20,77 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
type DtmTransInfo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"`
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"`
BranchID string `protobuf:"bytes,3,opt,name=BranchID,proto3" json:"BranchID,omitempty"`
Dtm string `protobuf:"bytes,4,opt,name=Dtm,proto3" json:"Dtm,omitempty"`
}
func (x *DtmTransInfo) Reset() {
*x = DtmTransInfo{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmcli_dtmcli_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DtmTransInfo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DtmTransInfo) ProtoMessage() {}
func (x *DtmTransInfo) ProtoReflect() protoreflect.Message {
mi := &file_dtmcli_dtmcli_proto_msgTypes[0]
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 DtmTransInfo.ProtoReflect.Descriptor instead.
func (*DtmTransInfo) Descriptor() ([]byte, []int) {
return file_dtmcli_dtmcli_proto_rawDescGZIP(), []int{0}
}
func (x *DtmTransInfo) GetGid() string {
if x != nil {
return x.Gid
}
return ""
}
func (x *DtmTransInfo) GetTransType() string {
if x != nil {
return x.TransType
}
return ""
}
func (x *DtmTransInfo) GetBranchID() string {
if x != nil {
return x.BranchID
}
return ""
}
func (x *DtmTransInfo) GetDtm() string {
if x != nil {
return x.Dtm
}
return ""
}
// The request message containing the user's name. // The request message containing the user's name.
type DtmRequest struct { type DtmRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
@ -29,14 +100,15 @@ type DtmRequest struct {
Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"` Gid string `protobuf:"bytes,1,opt,name=Gid,proto3" json:"Gid,omitempty"`
TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"` TransType string `protobuf:"bytes,2,opt,name=TransType,proto3" json:"TransType,omitempty"`
QueryPrepared string `protobuf:"bytes,3,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"` QueryPrepared string `protobuf:"bytes,3,opt,name=QueryPrepared,proto3" json:"QueryPrepared,omitempty"`
Extra map[string]string `protobuf:"bytes,4,rep,name=Extra,proto3" json:"Extra,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Method string `protobuf:"bytes,4,opt,name=Method,proto3" json:"Method,omitempty"`
AppData []byte `protobuf:"bytes,5,opt,name=AppData,proto3" json:"AppData,omitempty"` Extra map[string]string `protobuf:"bytes,5,rep,name=Extra,proto3" json:"Extra,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
AppData []byte `protobuf:"bytes,6,opt,name=AppData,proto3" json:"AppData,omitempty"`
} }
func (x *DtmRequest) Reset() { func (x *DtmRequest) Reset() {
*x = DtmRequest{} *x = DtmRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmcli_dtmcli_proto_msgTypes[0] mi := &file_dtmcli_dtmcli_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -49,7 +121,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_dtmcli_dtmcli_proto_msgTypes[0] mi := &file_dtmcli_dtmcli_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 {
@ -62,7 +134,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_dtmcli_dtmcli_proto_rawDescGZIP(), []int{0} return file_dtmcli_dtmcli_proto_rawDescGZIP(), []int{1}
} }
func (x *DtmRequest) GetGid() string { func (x *DtmRequest) GetGid() string {
@ -86,6 +158,13 @@ func (x *DtmRequest) GetQueryPrepared() string {
return "" return ""
} }
func (x *DtmRequest) GetMethod() string {
if x != nil {
return x.Method
}
return ""
}
func (x *DtmRequest) GetExtra() map[string]string { func (x *DtmRequest) GetExtra() map[string]string {
if x != nil { if x != nil {
return x.Extra return x.Extra
@ -106,13 +185,14 @@ type DtmReply struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
DtmResult string `protobuf:"bytes,1,opt,name=DtmResult,proto3" json:"DtmResult,omitempty"` DtmResult string `protobuf:"bytes,1,opt,name=DtmResult,proto3" json:"DtmResult,omitempty"`
DtmMessage string `protobuf:"bytes,2,opt,name=DtmMessage,proto3" json:"DtmMessage,omitempty"`
} }
func (x *DtmReply) Reset() { func (x *DtmReply) Reset() {
*x = DtmReply{} *x = DtmReply{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_dtmcli_dtmcli_proto_msgTypes[1] mi := &file_dtmcli_dtmcli_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -125,7 +205,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_dtmcli_dtmcli_proto_msgTypes[1] mi := &file_dtmcli_dtmcli_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 {
@ -138,7 +218,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_dtmcli_dtmcli_proto_rawDescGZIP(), []int{1} return file_dtmcli_dtmcli_proto_rawDescGZIP(), []int{2}
} }
func (x *DtmReply) GetDtmResult() string { func (x *DtmReply) GetDtmResult() string {
@ -148,35 +228,52 @@ func (x *DtmReply) GetDtmResult() string {
return "" return ""
} }
func (x *DtmReply) GetDtmMessage() string {
if x != nil {
return x.DtmMessage
}
return ""
}
var File_dtmcli_dtmcli_proto protoreflect.FileDescriptor var File_dtmcli_dtmcli_proto protoreflect.FileDescriptor
var file_dtmcli_dtmcli_proto_rawDesc = []byte{ var file_dtmcli_dtmcli_proto_rawDesc = []byte{
0x0a, 0x13, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x0a, 0x13, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x22, 0xeb, 0x01, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x22, 0x6c, 0x0a,
0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x0c, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x10, 0x0a,
0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x03, 0x47, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12,
0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x1c, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01,
0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x28, 0x09, 0x52, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a,
0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x01, 0x28, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x08, 0x42, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x49, 0x44, 0x12, 0x10, 0x0a, 0x03, 0x44, 0x74, 0x6d,
0x65, 0x64, 0x12, 0x33, 0x0a, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x04, 0x20, 0x03, 0x28, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x44, 0x74, 0x6d, 0x22, 0x83, 0x02, 0x0a, 0x0a,
0x0b, 0x32, 0x1d, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x47, 0x69,
0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x47, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09,
0x52, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x0d, 0x51, 0x75,
0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x09, 0x52, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x65, 0x70, 0x61, 0x72, 0x65, 0x64,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x28, 0x0a, 0x08, 0x44, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x33, 0x0a, 0x05, 0x45, 0x78, 0x74, 0x72,
0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x61, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69,
0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0x35, 0x0a, 0x03, 0x44, 0x74, 0x6d, 0x12, 0x2e, 0x0a, 0x04, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x18, 0x0a,
0x43, 0x61, 0x6c, 0x6c, 0x12, 0x12, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07,
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61,
0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
0x6f, 0x33, 0x01, 0x22, 0x48, 0x0a, 0x08, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1c, 0x0a,
0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x44,
0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x35, 0x0a, 0x03, 0x44,
0x74, 0x6d, 0x12, 0x2e, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x12, 0x2e, 0x64, 0x74, 0x6d,
0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10,
0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79,
0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -191,16 +288,17 @@ func file_dtmcli_dtmcli_proto_rawDescGZIP() []byte {
return file_dtmcli_dtmcli_proto_rawDescData return file_dtmcli_dtmcli_proto_rawDescData
} }
var file_dtmcli_dtmcli_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_dtmcli_dtmcli_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_dtmcli_dtmcli_proto_goTypes = []interface{}{ var file_dtmcli_dtmcli_proto_goTypes = []interface{}{
(*DtmRequest)(nil), // 0: dtmcli.DtmRequest (*DtmTransInfo)(nil), // 0: dtmcli.DtmTransInfo
(*DtmReply)(nil), // 1: dtmcli.DtmReply (*DtmRequest)(nil), // 1: dtmcli.DtmRequest
nil, // 2: dtmcli.DtmRequest.ExtraEntry (*DtmReply)(nil), // 2: dtmcli.DtmReply
nil, // 3: dtmcli.DtmRequest.ExtraEntry
} }
var file_dtmcli_dtmcli_proto_depIdxs = []int32{ var file_dtmcli_dtmcli_proto_depIdxs = []int32{
2, // 0: dtmcli.DtmRequest.Extra:type_name -> dtmcli.DtmRequest.ExtraEntry 3, // 0: dtmcli.DtmRequest.Extra:type_name -> dtmcli.DtmRequest.ExtraEntry
0, // 1: dtmcli.Dtm.Call:input_type -> dtmcli.DtmRequest 1, // 1: dtmcli.Dtm.Call:input_type -> dtmcli.DtmRequest
1, // 2: dtmcli.Dtm.Call:output_type -> dtmcli.DtmReply 2, // 2: dtmcli.Dtm.Call:output_type -> dtmcli.DtmReply
2, // [2:3] is the sub-list for method output_type 2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type 1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension type_name
@ -215,7 +313,7 @@ func file_dtmcli_dtmcli_proto_init() {
} }
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_dtmcli_dtmcli_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { file_dtmcli_dtmcli_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmRequest); i { switch v := v.(*DtmTransInfo); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@ -227,6 +325,18 @@ func file_dtmcli_dtmcli_proto_init() {
} }
} }
file_dtmcli_dtmcli_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { file_dtmcli_dtmcli_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DtmRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_dtmcli_dtmcli_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
@ -245,7 +355,7 @@ func file_dtmcli_dtmcli_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_dtmcli_dtmcli_proto_rawDesc, RawDescriptor: file_dtmcli_dtmcli_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 3, NumMessages: 4,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -9,6 +9,13 @@ service Dtm {
rpc Call(DtmRequest) returns (DtmReply) {} rpc Call(DtmRequest) returns (DtmReply) {}
} }
message DtmTransInfo {
string Gid = 1;
string TransType = 2;
string BranchID = 3;
string Dtm = 4;
}
// The request message containing the user's name. // The request message containing the user's name.
message DtmRequest { message DtmRequest {
string Gid = 1; string Gid = 1;

View File

@ -7,13 +7,13 @@ import (
pb "github.com/yedf/dtm/dtmcli" pb "github.com/yedf/dtm/dtmcli"
) )
// server is used to implement helloworld.GreeterServer. // dtmServer is used to implement helloworld.GreeterServer.
type server struct { type dtmServer struct {
pb.UnimplementedDtmServer pb.UnimplementedDtmServer
} }
// SayHello implements helloworld.GreeterServer // SayHello implements helloworld.GreeterServer
func (s *server) Call(ctx context.Context, in *pb.DtmRequest) (*pb.DtmReply, error) { func (s *dtmServer) Call(ctx context.Context, in *pb.DtmRequest) (*pb.DtmReply, error) {
log.Printf("Received: %v", in) log.Printf("Received: %v", in)
return &pb.DtmReply{}, nil return &pb.DtmReply{DtmResult: "SUCCESS", DtmMessage: "ok"}, nil
} }

View File

@ -2,7 +2,6 @@ package dtmsvr
import ( import (
"fmt" "fmt"
"log"
"net" "net"
"time" "time"
@ -13,7 +12,7 @@ import (
) )
var dtmsvrPort = 8080 var dtmsvrPort = 8080
var dtmsvrGrpcPort = 50051 var dtmsvrGrpcPort = 50081
// StartSvr StartSvr // StartSvr StartSvr
func StartSvr() { func StartSvr() {
@ -24,16 +23,13 @@ func StartSvr() {
go app.Run(fmt.Sprintf(":%d", dtmsvrPort)) go app.Run(fmt.Sprintf(":%d", dtmsvrPort))
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", dtmsvrGrpcPort)) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", dtmsvrGrpcPort))
if err != nil { dtmcli.FatalIfError(err)
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer() s := grpc.NewServer()
dtmcli.RegisterDtmServer(s, &server{}) dtmcli.RegisterDtmServer(s, &dtmServer{})
log.Printf("server listening at %v", lis.Addr()) dtmcli.Logf("grpc listening at %v", lis.Addr())
go func() { go func() {
if err := s.Serve(lis); err != nil { err := s.Serve(lis)
log.Fatalf("failed to serve: %v", err) dtmcli.FatalIfError(err)
}
}() }()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)

View File

@ -7,6 +7,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"
grpc "google.golang.org/grpc"
) )
const ( const (
@ -14,11 +15,16 @@ const (
BusiAPI = "/api/busi" BusiAPI = "/api/busi"
// BusiPort busi server port // BusiPort busi server port
BusiPort = 8081 BusiPort = 8081
// BusiPbPort busi server port
BusiPbPort = 50081
) )
// 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)
// DtmClient grpc client for dtm
var DtmClient dtmcli.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")
@ -26,6 +32,12 @@ func BaseAppStartup() *gin.Engine {
BaseAddRoute(app) BaseAddRoute(app)
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())
dtmcli.FatalIfError(err)
DtmClient = dtmcli.NewDtmClient(conn)
dtmcli.Logf("dtm client inited")
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
return app return app
} }

View File

@ -17,6 +17,9 @@ type M = map[string]interface{}
// DtmServer dtm service address // DtmServer dtm service address
const DtmServer = "http://localhost:8080/api/dtmsvr" const DtmServer = "http://localhost:8080/api/dtmsvr"
// DtmGrpcServer dtm grpc service address
const DtmGrpcServer = "localhost:50081"
// TransReq transaction request payload // TransReq transaction request payload
type TransReq struct { type TransReq struct {
Amount int `json:"amount"` Amount int `json:"amount"`