server call busi seems ok

This commit is contained in:
yedf2 2021-08-09 14:45:12 +08:00
parent 4eb098b0be
commit 0d0c868374
10 changed files with 367 additions and 284 deletions

View File

@ -235,6 +235,126 @@ func (x *DtmReply) GetDtmMessage() string {
return "" return ""
} }
// The request message containing the user's name.
type BusiRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Info *DtmTransInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"`
Extra map[string]string `protobuf:"bytes,2,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,3,opt,name=AppData,proto3" json:"AppData,omitempty"`
}
func (x *BusiRequest) Reset() {
*x = BusiRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmcli_dtmcli_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *BusiRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BusiRequest) ProtoMessage() {}
func (x *BusiRequest) ProtoReflect() protoreflect.Message {
mi := &file_dtmcli_dtmcli_proto_msgTypes[3]
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 BusiRequest.ProtoReflect.Descriptor instead.
func (*BusiRequest) Descriptor() ([]byte, []int) {
return file_dtmcli_dtmcli_proto_rawDescGZIP(), []int{3}
}
func (x *BusiRequest) GetInfo() *DtmTransInfo {
if x != nil {
return x.Info
}
return nil
}
func (x *BusiRequest) GetExtra() map[string]string {
if x != nil {
return x.Extra
}
return nil
}
func (x *BusiRequest) GetAppData() []byte {
if x != nil {
return x.AppData
}
return nil
}
// The response message containing the greetings
type BusiReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
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 *BusiReply) Reset() {
*x = BusiReply{}
if protoimpl.UnsafeEnabled {
mi := &file_dtmcli_dtmcli_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *BusiReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BusiReply) ProtoMessage() {}
func (x *BusiReply) ProtoReflect() protoreflect.Message {
mi := &file_dtmcli_dtmcli_proto_msgTypes[4]
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 BusiReply.ProtoReflect.Descriptor instead.
func (*BusiReply) Descriptor() ([]byte, []int) {
return file_dtmcli_dtmcli_proto_rawDescGZIP(), []int{4}
}
func (x *BusiReply) GetDtmResult() string {
if x != nil {
return x.DtmResult
}
return ""
}
func (x *BusiReply) 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{
@ -267,13 +387,30 @@ var file_dtmcli_dtmcli_proto_rawDesc = []byte{
0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 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, 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, 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, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xc1, 0x01, 0x0a, 0x0b,
0x74, 0x6d, 0x12, 0x2e, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x12, 0x2e, 0x64, 0x74, 0x6d, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x04, 0x69,
0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x63,
0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x34, 0x0a, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x02,
0x2f, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45,
0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x41,
0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x41, 0x70,
0x70, 0x44, 0x61, 0x74, 0x61, 0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e,
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22,
0x49, 0x0a, 0x09, 0x42, 0x75, 0x73, 0x69, 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 (
@ -288,22 +425,27 @@ 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, 4) var file_dtmcli_dtmcli_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_dtmcli_dtmcli_proto_goTypes = []interface{}{ var file_dtmcli_dtmcli_proto_goTypes = []interface{}{
(*DtmTransInfo)(nil), // 0: dtmcli.DtmTransInfo (*DtmTransInfo)(nil), // 0: dtmcli.DtmTransInfo
(*DtmRequest)(nil), // 1: dtmcli.DtmRequest (*DtmRequest)(nil), // 1: dtmcli.DtmRequest
(*DtmReply)(nil), // 2: dtmcli.DtmReply (*DtmReply)(nil), // 2: dtmcli.DtmReply
nil, // 3: dtmcli.DtmRequest.ExtraEntry (*BusiRequest)(nil), // 3: dtmcli.BusiRequest
(*BusiReply)(nil), // 4: dtmcli.BusiReply
nil, // 5: dtmcli.DtmRequest.ExtraEntry
nil, // 6: dtmcli.BusiRequest.ExtraEntry
} }
var file_dtmcli_dtmcli_proto_depIdxs = []int32{ var file_dtmcli_dtmcli_proto_depIdxs = []int32{
3, // 0: dtmcli.DtmRequest.Extra:type_name -> dtmcli.DtmRequest.ExtraEntry 5, // 0: dtmcli.DtmRequest.Extra:type_name -> dtmcli.DtmRequest.ExtraEntry
1, // 1: dtmcli.Dtm.Call:input_type -> dtmcli.DtmRequest 0, // 1: dtmcli.BusiRequest.info:type_name -> dtmcli.DtmTransInfo
2, // 2: dtmcli.Dtm.Call:output_type -> dtmcli.DtmReply 6, // 2: dtmcli.BusiRequest.Extra:type_name -> dtmcli.BusiRequest.ExtraEntry
2, // [2:3] is the sub-list for method output_type 1, // 3: dtmcli.Dtm.Call:input_type -> dtmcli.DtmRequest
1, // [1:2] is the sub-list for method input_type 2, // 4: dtmcli.Dtm.Call:output_type -> dtmcli.DtmReply
1, // [1:1] is the sub-list for extension type_name 4, // [4:5] is the sub-list for method output_type
1, // [1:1] is the sub-list for extension extendee 3, // [3:4] is the sub-list for method input_type
0, // [0:1] is the sub-list for field type_name 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
} }
func init() { file_dtmcli_dtmcli_proto_init() } func init() { file_dtmcli_dtmcli_proto_init() }
@ -348,6 +490,30 @@ func file_dtmcli_dtmcli_proto_init() {
return nil return nil
} }
} }
file_dtmcli_dtmcli_proto_msgTypes[3].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_dtmcli_dtmcli_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -355,7 +521,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: 4, NumMessages: 7,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -31,3 +31,16 @@ message DtmReply {
string DtmResult = 1; string DtmResult = 1;
string DtmMessage = 2; string DtmMessage = 2;
} }
// The request message containing the user's name.
message BusiRequest {
dtmcli.DtmTransInfo info = 1;
map<string, string> Extra = 2;
bytes AppData = 3;
}
// The response message containing the greetings
message BusiReply {
string DtmResult = 1;
string DtmMessage = 2;
}

View File

@ -1,6 +1,7 @@
package dtmcli package dtmcli
import ( import (
"context"
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"errors" "errors"
@ -13,6 +14,7 @@ import (
"time" "time"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
grpc "google.golang.org/grpc"
) )
// P2E panic to error // P2E panic to error
@ -269,3 +271,19 @@ func CheckResult(res interface{}, err error) error {
} }
return err return err
} }
// GrpcServerLog 打印grpc服务端的日志
func GrpcServerLog(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
Logf("grpc server handling: %s %v", info.FullMethod, req)
m, err := handler(ctx, req)
Logf("grpc server handled: %s %v result: %v err: %v", info.FullMethod, req, m, err)
return m, err
}
// GrpcClientLog 打印grpc服务端的日志
func GrpcClientLog(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
Logf("grpc client calling: %s%s %v", cc.Target(), method, req)
err := invoker(ctx, method, req, reply, cc, opts...)
Logf("grpc client called: %s%s %v result: %v err: %v", cc.Target(), method, req, reply, err)
return err
}

View File

@ -3,8 +3,11 @@ package dtmsvr
import ( import (
"context" "context"
"log" "log"
"strings"
"github.com/yedf/dtm/dtmcli"
pb "github.com/yedf/dtm/dtmcli" pb "github.com/yedf/dtm/dtmcli"
"google.golang.org/grpc"
) )
// dtmServer is used to implement helloworld.GreeterServer. // dtmServer is used to implement helloworld.GreeterServer.
@ -14,6 +17,19 @@ type dtmServer struct {
// SayHello implements helloworld.GreeterServer // SayHello implements helloworld.GreeterServer
func (s *dtmServer) 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("dtmServer Received: %v", in)
dynamicCallPb(ctx, in, in.Extra["BusiFunc"], in.AppData)
return &pb.DtmReply{DtmResult: "SUCCESS", DtmMessage: "ok"}, nil return &pb.DtmReply{DtmResult: "SUCCESS", DtmMessage: "ok"}, nil
} }
func dynamicCallPb(ctx context.Context, in *pb.DtmRequest, pbAddr string, data []byte) error {
fs := strings.Split(pbAddr, "/")
grpcAddr := fs[0]
method := "/" + strings.Join(fs[1:], "/")
conn, err := grpc.Dial(grpcAddr, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(dtmcli.GrpcClientLog))
dtmcli.FatalIfError(err)
reply := &dtmcli.BusiReply{}
err = conn.Invoke(ctx, method, &dtmcli.BusiRequest{Info: &dtmcli.DtmTransInfo{Gid: in.Gid}}, reply)
dtmcli.FatalIfError(err)
return err
}

View File

@ -24,7 +24,7 @@ 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() s := grpc.NewServer(grpc.UnaryInterceptor(dtmcli.GrpcServerLog))
dtmcli.RegisterDtmServer(s, &dtmServer{}) dtmcli.RegisterDtmServer(s, &dtmServer{})
dtmcli.Logf("grpc listening at %v", lis.Addr()) dtmcli.Logf("grpc listening at %v", lis.Addr())
go func() { go func() {

View File

@ -11,7 +11,6 @@ import (
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"
reflect "reflect" reflect "reflect"
sync "sync"
) )
const ( const (
@ -21,205 +20,55 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
) )
// The request message containing the user's name.
type BusiRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Info *dtmcli.DtmTransInfo `protobuf:"bytes,1,opt,name=info,proto3" json:"info,omitempty"`
Extra map[string]string `protobuf:"bytes,2,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,3,opt,name=AppData,proto3" json:"AppData,omitempty"`
}
func (x *BusiRequest) Reset() {
*x = BusiRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_examples_busi_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *BusiRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BusiRequest) ProtoMessage() {}
func (x *BusiRequest) ProtoReflect() protoreflect.Message {
mi := &file_examples_busi_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 BusiRequest.ProtoReflect.Descriptor instead.
func (*BusiRequest) Descriptor() ([]byte, []int) {
return file_examples_busi_proto_rawDescGZIP(), []int{0}
}
func (x *BusiRequest) GetInfo() *dtmcli.DtmTransInfo {
if x != nil {
return x.Info
}
return nil
}
func (x *BusiRequest) GetExtra() map[string]string {
if x != nil {
return x.Extra
}
return nil
}
func (x *BusiRequest) GetAppData() []byte {
if x != nil {
return x.AppData
}
return nil
}
// The response message containing the greetings
type BusiReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
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 *BusiReply) Reset() {
*x = BusiReply{}
if protoimpl.UnsafeEnabled {
mi := &file_examples_busi_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *BusiReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*BusiReply) ProtoMessage() {}
func (x *BusiReply) ProtoReflect() protoreflect.Message {
mi := &file_examples_busi_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 BusiReply.ProtoReflect.Descriptor instead.
func (*BusiReply) Descriptor() ([]byte, []int) {
return file_examples_busi_proto_rawDescGZIP(), []int{1}
}
func (x *BusiReply) GetDtmResult() string {
if x != nil {
return x.DtmResult
}
return ""
}
func (x *BusiReply) GetDtmMessage() string {
if x != nil {
return x.DtmMessage
}
return ""
}
var File_examples_busi_proto protoreflect.FileDescriptor var File_examples_busi_proto protoreflect.FileDescriptor
var file_examples_busi_proto_rawDesc = []byte{ var file_examples_busi_proto_rawDesc = []byte{
0x0a, 0x13, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x75, 0x73, 0x69, 0x2e, 0x0a, 0x13, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x75, 0x73, 0x69, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x1a, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x1a,
0x13, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x70, 0x13, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2f, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x01, 0x0a, 0x0b, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x9a, 0x02, 0x0a, 0x04, 0x42, 0x75, 0x73, 0x69, 0x12, 0x30, 0x0a,
0x75, 0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42,
0x28, 0x0b, 0x32, 0x14, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x44, 0x74, 0x6d, 0x54, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x64, 0x74, 0x6d,
0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x36, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12,
0x0a, 0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x33, 0x0a, 0x07, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d,
0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x11, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70,
0x05, 0x45, 0x78, 0x74, 0x72, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x34, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x75, 0x74,
0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x41, 0x70, 0x70, 0x44, 0x61, 0x74, 0x61, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65,
0x1a, 0x38, 0x0a, 0x0a, 0x45, 0x78, 0x74, 0x72, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42,
0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x39, 0x0a, 0x0d, 0x54, 0x72,
0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x49, 0x0a, 0x09, 0x42, 0x75, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x65, 0x1a, 0x11, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65,
0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x44, 0x74, 0x6d, 0x52, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x75,
0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x73, 0x73, 0x74, 0x52, 0x65, 0x76, 0x65, 0x72, 0x74, 0x12, 0x13, 0x2e, 0x64, 0x74, 0x6d, 0x63, 0x6c, 0x69,
0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x44, 0x74, 0x6d, 0x4d, 0x65, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x64,
0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xf8, 0x01, 0x0a, 0x04, 0x42, 0x75, 0x73, 0x69, 0x12, 0x37, 0x74, 0x6d, 0x63, 0x6c, 0x69, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22,
0x0a, 0x07, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x00, 0x42, 0x1e, 0x5a, 0x1c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x79, 0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x12, 0x38, 0x0a, 0x08, 0x54, 0x72, 0x61, 0x6e, 0x73,
0x4f, 0x75, 0x74, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42,
0x75, 0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61,
0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22,
0x00, 0x12, 0x3d, 0x0a, 0x0d, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x49, 0x6e, 0x52, 0x65, 0x76, 0x65,
0x72, 0x74, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75,
0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00,
0x12, 0x3e, 0x0a, 0x0e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4f, 0x75, 0x74, 0x52, 0x65, 0x76, 0x65,
0x72, 0x74, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75,
0x73, 0x69, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x73, 0x2e, 0x42, 0x75, 0x73, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00,
0x42, 0x1e, 0x5a, 0x1c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x79,
0x65, 0x64, 0x66, 0x2f, 0x64, 0x74, 0x6d, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var (
file_examples_busi_proto_rawDescOnce sync.Once
file_examples_busi_proto_rawDescData = file_examples_busi_proto_rawDesc
)
func file_examples_busi_proto_rawDescGZIP() []byte {
file_examples_busi_proto_rawDescOnce.Do(func() {
file_examples_busi_proto_rawDescData = protoimpl.X.CompressGZIP(file_examples_busi_proto_rawDescData)
})
return file_examples_busi_proto_rawDescData
}
var file_examples_busi_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_examples_busi_proto_goTypes = []interface{}{ var file_examples_busi_proto_goTypes = []interface{}{
(*BusiRequest)(nil), // 0: examples.BusiRequest (*dtmcli.BusiRequest)(nil), // 0: dtmcli.BusiRequest
(*BusiReply)(nil), // 1: examples.BusiReply (*dtmcli.BusiReply)(nil), // 1: dtmcli.BusiReply
nil, // 2: examples.BusiRequest.ExtraEntry
(*dtmcli.DtmTransInfo)(nil), // 3: dtmcli.DtmTransInfo
} }
var file_examples_busi_proto_depIdxs = []int32{ var file_examples_busi_proto_depIdxs = []int32{
3, // 0: examples.BusiRequest.info:type_name -> dtmcli.DtmTransInfo 0, // 0: examples.Busi.Call:input_type -> dtmcli.BusiRequest
2, // 1: examples.BusiRequest.Extra:type_name -> examples.BusiRequest.ExtraEntry 0, // 1: examples.Busi.TransIn:input_type -> dtmcli.BusiRequest
0, // 2: examples.Busi.TransIn:input_type -> examples.BusiRequest 0, // 2: examples.Busi.TransOut:input_type -> dtmcli.BusiRequest
0, // 3: examples.Busi.TransOut:input_type -> examples.BusiRequest 0, // 3: examples.Busi.TransInRevert:input_type -> dtmcli.BusiRequest
0, // 4: examples.Busi.TransInRevert:input_type -> examples.BusiRequest 0, // 4: examples.Busi.TransOutRevert:input_type -> dtmcli.BusiRequest
0, // 5: examples.Busi.TransOutRevert:input_type -> examples.BusiRequest 1, // 5: examples.Busi.Call:output_type -> dtmcli.BusiReply
1, // 6: examples.Busi.TransIn:output_type -> examples.BusiReply 1, // 6: examples.Busi.TransIn:output_type -> dtmcli.BusiReply
1, // 7: examples.Busi.TransOut:output_type -> examples.BusiReply 1, // 7: examples.Busi.TransOut:output_type -> dtmcli.BusiReply
1, // 8: examples.Busi.TransInRevert:output_type -> examples.BusiReply 1, // 8: examples.Busi.TransInRevert:output_type -> dtmcli.BusiReply
1, // 9: examples.Busi.TransOutRevert:output_type -> examples.BusiReply 1, // 9: examples.Busi.TransOutRevert:output_type -> dtmcli.BusiReply
6, // [6:10] is the sub-list for method output_type 5, // [5:10] is the sub-list for method output_type
2, // [2:6] is the sub-list for method input_type 0, // [0:5] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
} }
func init() { file_examples_busi_proto_init() } func init() { file_examples_busi_proto_init() }
@ -227,45 +76,18 @@ func file_examples_busi_proto_init() {
if File_examples_busi_proto != nil { if File_examples_busi_proto != nil {
return return
} }
if !protoimpl.UnsafeEnabled {
file_examples_busi_proto_msgTypes[0].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_examples_busi_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*BusiReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_examples_busi_proto_rawDesc, RawDescriptor: file_examples_busi_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 3, NumMessages: 0,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },
GoTypes: file_examples_busi_proto_goTypes, GoTypes: file_examples_busi_proto_goTypes,
DependencyIndexes: file_examples_busi_proto_depIdxs, DependencyIndexes: file_examples_busi_proto_depIdxs,
MessageInfos: file_examples_busi_proto_msgTypes,
}.Build() }.Build()
File_examples_busi_proto = out.File File_examples_busi_proto = out.File
file_examples_busi_proto_rawDesc = nil file_examples_busi_proto_rawDesc = nil

View File

@ -7,21 +7,11 @@ import "dtmcli/dtmcli.proto";
// The dtm service definition. // The dtm service definition.
service Busi { service Busi {
rpc TransIn(BusiRequest) returns (BusiReply) {} rpc Call(dtmcli.BusiRequest) returns (dtmcli.BusiReply) {}
rpc TransOut(BusiRequest) returns (BusiReply) {}
rpc TransInRevert(BusiRequest) returns (BusiReply) {} rpc TransIn(dtmcli.BusiRequest) returns (dtmcli.BusiReply) {}
rpc TransOutRevert(BusiRequest) returns (BusiReply) {} rpc TransOut(dtmcli.BusiRequest) returns (dtmcli.BusiReply) {}
rpc TransInRevert(dtmcli.BusiRequest) returns (dtmcli.BusiReply) {}
rpc TransOutRevert(dtmcli.BusiRequest) returns (dtmcli.BusiReply) {}
} }
// The request message containing the user's name.
message BusiRequest {
dtmcli.DtmTransInfo info = 1;
map<string, string> Extra = 2;
bytes AppData = 3;
}
// The response message containing the greetings
message BusiReply {
string DtmResult = 1;
string DtmMessage = 2;
}

View File

@ -4,6 +4,7 @@ package examples
import ( import (
context "context" context "context"
dtmcli "github.com/yedf/dtm/dtmcli"
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"
@ -18,10 +19,11 @@ 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 *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) Call(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error)
TransOut(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) TransIn(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error)
TransInRevert(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) TransOut(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error)
TransOutRevert(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) TransInRevert(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error)
TransOutRevert(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error)
} }
type busiClient struct { type busiClient struct {
@ -32,8 +34,17 @@ func NewBusiClient(cc grpc.ClientConnInterface) BusiClient {
return &busiClient{cc} return &busiClient{cc}
} }
func (c *busiClient) TransIn(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) { func (c *busiClient) Call(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error) {
out := new(BusiReply) out := new(dtmcli.BusiReply)
err := c.cc.Invoke(ctx, "/examples.Busi/Call", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *busiClient) TransIn(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error) {
out := new(dtmcli.BusiReply)
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 {
return nil, err return nil, err
@ -41,8 +52,8 @@ func (c *busiClient) TransIn(ctx context.Context, in *BusiRequest, opts ...grpc.
return out, nil return out, nil
} }
func (c *busiClient) TransOut(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) { func (c *busiClient) TransOut(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error) {
out := new(BusiReply) out := new(dtmcli.BusiReply)
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 {
return nil, err return nil, err
@ -50,8 +61,8 @@ func (c *busiClient) TransOut(ctx context.Context, in *BusiRequest, opts ...grpc
return out, nil return out, nil
} }
func (c *busiClient) TransInRevert(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) { func (c *busiClient) TransInRevert(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error) {
out := new(BusiReply) out := new(dtmcli.BusiReply)
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 {
return nil, err return nil, err
@ -59,8 +70,8 @@ func (c *busiClient) TransInRevert(ctx context.Context, in *BusiRequest, opts ..
return out, nil return out, nil
} }
func (c *busiClient) TransOutRevert(ctx context.Context, in *BusiRequest, opts ...grpc.CallOption) (*BusiReply, error) { func (c *busiClient) TransOutRevert(ctx context.Context, in *dtmcli.BusiRequest, opts ...grpc.CallOption) (*dtmcli.BusiReply, error) {
out := new(BusiReply) out := new(dtmcli.BusiReply)
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 {
return nil, err return nil, err
@ -72,10 +83,11 @@ func (c *busiClient) TransOutRevert(ctx context.Context, in *BusiRequest, opts .
// 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, *BusiRequest) (*BusiReply, error) Call(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error)
TransOut(context.Context, *BusiRequest) (*BusiReply, error) TransIn(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error)
TransInRevert(context.Context, *BusiRequest) (*BusiReply, error) TransOut(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error)
TransOutRevert(context.Context, *BusiRequest) (*BusiReply, error) TransInRevert(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error)
TransOutRevert(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error)
mustEmbedUnimplementedBusiServer() mustEmbedUnimplementedBusiServer()
} }
@ -83,16 +95,19 @@ type BusiServer interface {
type UnimplementedBusiServer struct { type UnimplementedBusiServer struct {
} }
func (UnimplementedBusiServer) TransIn(context.Context, *BusiRequest) (*BusiReply, error) { func (UnimplementedBusiServer) Call(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Call not implemented")
}
func (UnimplementedBusiServer) TransIn(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, 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, *BusiRequest) (*BusiReply, error) { func (UnimplementedBusiServer) TransOut(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, 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, *BusiRequest) (*BusiReply, error) { func (UnimplementedBusiServer) TransInRevert(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, 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, *BusiRequest) (*BusiReply, error) { func (UnimplementedBusiServer) TransOutRevert(context.Context, *dtmcli.BusiRequest) (*dtmcli.BusiReply, 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() {}
@ -108,8 +123,26 @@ func RegisterBusiServer(s grpc.ServiceRegistrar, srv BusiServer) {
s.RegisterService(&Busi_ServiceDesc, srv) s.RegisterService(&Busi_ServiceDesc, srv)
} }
func _Busi_Call_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(dtmcli.BusiRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(BusiServer).Call(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/examples.Busi/Call",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BusiServer).Call(ctx, req.(*dtmcli.BusiRequest))
}
return interceptor(ctx, in, info, handler)
}
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(BusiRequest) in := new(dtmcli.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -121,13 +154,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.(*BusiRequest)) return srv.(BusiServer).TransIn(ctx, req.(*dtmcli.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(BusiRequest) in := new(dtmcli.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -139,13 +172,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.(*BusiRequest)) return srv.(BusiServer).TransOut(ctx, req.(*dtmcli.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(BusiRequest) in := new(dtmcli.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -157,13 +190,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.(*BusiRequest)) return srv.(BusiServer).TransInRevert(ctx, req.(*dtmcli.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(BusiRequest) in := new(dtmcli.BusiRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -175,7 +208,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.(*BusiRequest)) return srv.(BusiServer).TransOutRevert(ctx, req.(*dtmcli.BusiRequest))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
@ -187,6 +220,10 @@ var Busi_ServiceDesc = grpc.ServiceDesc{
ServiceName: "examples.Busi", ServiceName: "examples.Busi",
HandlerType: (*BusiServer)(nil), HandlerType: (*BusiServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{
MethodName: "Call",
Handler: _Busi_Call_Handler,
},
{ {
MethodName: "TransIn", MethodName: "TransIn",
Handler: _Busi_TransIn_Handler, Handler: _Busi_TransIn_Handler,

View File

@ -2,6 +2,7 @@ package examples
import ( import (
"fmt" "fmt"
"net"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -16,12 +17,15 @@ const (
// BusiPort busi server port // BusiPort busi server port
BusiPort = 8081 BusiPort = 8081
// BusiPbPort busi server port // BusiPbPort busi server port
BusiPbPort = 50081 BusiPbPort = 60081
) )
// 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 // DtmClient grpc client for dtm
var DtmClient dtmcli.DtmClient = nil var DtmClient dtmcli.DtmClient = nil
@ -33,11 +37,21 @@ 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()) conn, err := grpc.Dial(DtmGrpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(dtmcli.GrpcClientLog))
dtmcli.FatalIfError(err) dtmcli.FatalIfError(err)
DtmClient = dtmcli.NewDtmClient(conn) DtmClient = dtmcli.NewDtmClient(conn)
dtmcli.Logf("dtm client inited") dtmcli.Logf("dtm client inited")
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", BusiPbPort))
dtmcli.FatalIfError(err)
s := grpc.NewServer(grpc.UnaryInterceptor(dtmcli.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
} }

View File

@ -15,7 +15,14 @@ func MsgPbSetup(app *gin.Engine) {
// MsgPbFireRequest 1 // MsgPbFireRequest 1
func MsgPbFireRequest() string { func MsgPbFireRequest() string {
dtmcli.Logf("MsgPbFireRequest") dtmcli.Logf("MsgPbFireRequest")
reply, err := DtmClient.Call(context.Background(), &dtmcli.DtmRequest{}) reply, err := DtmClient.Call(context.Background(), &dtmcli.DtmRequest{
Gid: "pb_test",
TransType: "msg",
Method: "submit",
Extra: dtmcli.MS{
"BusiFunc": BusiPb + "/examples.Busi/Call",
},
})
dtmcli.Logf("reply and err is: %v, %v", reply, err) dtmcli.Logf("reply and err is: %v, %v", reply, err)
return "" return ""
} }