Browse Source

添加服务治理

Tao Zhang 5 năm trước cách đây
mục cha
commit
14458d07b9
2 tập tin đã thay đổi với 481 bổ sung0 xóa
  1. 446 0
      proto/service.pb.go
  2. 35 0
      proto_src/service.proto

+ 446 - 0
proto/service.pb.go

@@ -0,0 +1,446 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: service.proto
+
+//声明 包名
+
+package proto
+
+import (
+	context "context"
+	fmt "fmt"
+	proto "github.com/golang/protobuf/proto"
+	grpc "google.golang.org/grpc"
+	codes "google.golang.org/grpc/codes"
+	status "google.golang.org/grpc/status"
+	math "math"
+)
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
+
+//服务参数
+type ServiceMeta struct {
+	ServiceName          string   `protobuf:"bytes,1,opt,name=serviceName,proto3" json:"serviceName,omitempty"`
+	ServiceAddr          string   `protobuf:"bytes,2,opt,name=serviceAddr,proto3" json:"serviceAddr,omitempty"`
+	Workers              int32    `protobuf:"varint,3,opt,name=workers,proto3" json:"workers,omitempty"`
+	Balance              int32    `protobuf:"varint,4,opt,name=balance,proto3" json:"balance,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *ServiceMeta) Reset()         { *m = ServiceMeta{} }
+func (m *ServiceMeta) String() string { return proto.CompactTextString(m) }
+func (*ServiceMeta) ProtoMessage()    {}
+func (*ServiceMeta) Descriptor() ([]byte, []int) {
+	return fileDescriptor_a0b84a42fa06f626, []int{0}
+}
+
+func (m *ServiceMeta) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_ServiceMeta.Unmarshal(m, b)
+}
+func (m *ServiceMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_ServiceMeta.Marshal(b, m, deterministic)
+}
+func (m *ServiceMeta) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_ServiceMeta.Merge(m, src)
+}
+func (m *ServiceMeta) XXX_Size() int {
+	return xxx_messageInfo_ServiceMeta.Size(m)
+}
+func (m *ServiceMeta) XXX_DiscardUnknown() {
+	xxx_messageInfo_ServiceMeta.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ServiceMeta proto.InternalMessageInfo
+
+func (m *ServiceMeta) GetServiceName() string {
+	if m != nil {
+		return m.ServiceName
+	}
+	return ""
+}
+
+func (m *ServiceMeta) GetServiceAddr() string {
+	if m != nil {
+		return m.ServiceAddr
+	}
+	return ""
+}
+
+func (m *ServiceMeta) GetWorkers() int32 {
+	if m != nil {
+		return m.Workers
+	}
+	return 0
+}
+
+func (m *ServiceMeta) GetBalance() int32 {
+	if m != nil {
+		return m.Balance
+	}
+	return 0
+}
+
+//标准字符串返回结果
+type StringReq struct {
+	Data                 string   `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *StringReq) Reset()         { *m = StringReq{} }
+func (m *StringReq) String() string { return proto.CompactTextString(m) }
+func (*StringReq) ProtoMessage()    {}
+func (*StringReq) Descriptor() ([]byte, []int) {
+	return fileDescriptor_a0b84a42fa06f626, []int{1}
+}
+
+func (m *StringReq) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_StringReq.Unmarshal(m, b)
+}
+func (m *StringReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_StringReq.Marshal(b, m, deterministic)
+}
+func (m *StringReq) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_StringReq.Merge(m, src)
+}
+func (m *StringReq) XXX_Size() int {
+	return xxx_messageInfo_StringReq.Size(m)
+}
+func (m *StringReq) XXX_DiscardUnknown() {
+	xxx_messageInfo_StringReq.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_StringReq proto.InternalMessageInfo
+
+func (m *StringReq) GetData() string {
+	if m != nil {
+		return m.Data
+	}
+	return ""
+}
+
+//
+type ApplyReqData struct {
+	ServiceName          string   `protobuf:"bytes,1,opt,name=serviceName,proto3" json:"serviceName,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *ApplyReqData) Reset()         { *m = ApplyReqData{} }
+func (m *ApplyReqData) String() string { return proto.CompactTextString(m) }
+func (*ApplyReqData) ProtoMessage()    {}
+func (*ApplyReqData) Descriptor() ([]byte, []int) {
+	return fileDescriptor_a0b84a42fa06f626, []int{2}
+}
+
+func (m *ApplyReqData) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_ApplyReqData.Unmarshal(m, b)
+}
+func (m *ApplyReqData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_ApplyReqData.Marshal(b, m, deterministic)
+}
+func (m *ApplyReqData) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_ApplyReqData.Merge(m, src)
+}
+func (m *ApplyReqData) XXX_Size() int {
+	return xxx_messageInfo_ApplyReqData.Size(m)
+}
+func (m *ApplyReqData) XXX_DiscardUnknown() {
+	xxx_messageInfo_ApplyReqData.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ApplyReqData proto.InternalMessageInfo
+
+func (m *ApplyReqData) GetServiceName() string {
+	if m != nil {
+		return m.ServiceName
+	}
+	return ""
+}
+
+type ApplyRepData struct {
+	ServiceAddr          string   `protobuf:"bytes,1,opt,name=serviceAddr,proto3" json:"serviceAddr,omitempty"`
+	ServiceResourceId    string   `protobuf:"bytes,2,opt,name=serviceResourceId,proto3" json:"serviceResourceId,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *ApplyRepData) Reset()         { *m = ApplyRepData{} }
+func (m *ApplyRepData) String() string { return proto.CompactTextString(m) }
+func (*ApplyRepData) ProtoMessage()    {}
+func (*ApplyRepData) Descriptor() ([]byte, []int) {
+	return fileDescriptor_a0b84a42fa06f626, []int{3}
+}
+
+func (m *ApplyRepData) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_ApplyRepData.Unmarshal(m, b)
+}
+func (m *ApplyRepData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_ApplyRepData.Marshal(b, m, deterministic)
+}
+func (m *ApplyRepData) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_ApplyRepData.Merge(m, src)
+}
+func (m *ApplyRepData) XXX_Size() int {
+	return xxx_messageInfo_ApplyRepData.Size(m)
+}
+func (m *ApplyRepData) XXX_DiscardUnknown() {
+	xxx_messageInfo_ApplyRepData.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_ApplyRepData proto.InternalMessageInfo
+
+func (m *ApplyRepData) GetServiceAddr() string {
+	if m != nil {
+		return m.ServiceAddr
+	}
+	return ""
+}
+
+func (m *ApplyRepData) GetServiceResourceId() string {
+	if m != nil {
+		return m.ServiceResourceId
+	}
+	return ""
+}
+
+func init() {
+	proto.RegisterType((*ServiceMeta)(nil), "proto.ServiceMeta")
+	proto.RegisterType((*StringReq)(nil), "proto.StringReq")
+	proto.RegisterType((*ApplyReqData)(nil), "proto.ApplyReqData")
+	proto.RegisterType((*ApplyRepData)(nil), "proto.ApplyRepData")
+}
+
+func init() {
+	proto.RegisterFile("service.proto", fileDescriptor_a0b84a42fa06f626)
+}
+
+var fileDescriptor_a0b84a42fa06f626 = []byte{
+	// 272 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 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14,
+	0x3c, 0x24, 0xa6, 0x3f, 0x0c, 0xd2, 0x30, 0x1d, 0x3e, 0x42, 0x2a, 0x69, 0x5d, 0x5a, 0x47, 0x88,
+	0xed, 0xc0, 0x93, 0x68, 0xd5, 0xd1, 0x75, 0x87, 0x75, 0x15, 0x45, 0xaf, 0xb1, 0x2c, 0xc8, 0x3a,
+	0x6d, 0x76, 0x27, 0x5b, 0x66, 0x90, 0xf8, 0x46, 0x78, 0x1b, 0xc8, 0x78, 0x91, 0xd1, 0x1e, 0xe8,
+	0x4b, 0x8b, 0x1e, 0x4e, 0x9b, 0x68, 0x15, 0x29, 0x4b, 0x78, 0x4c, 0x71, 0xec, 0xa1, 0xd5, 0x85,
+	0x87, 0x66, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdb, 0x8e, 0x00, 0x87, 0x34, 0x02, 0x00, 0x00,
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConnInterface
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion6
+
+// ServiceClient is the client API for Service service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
+type ServiceClient interface {
+	//注册服务
+	Registe(ctx context.Context, in *ServiceMeta, opts ...grpc.CallOption) (*StringReq, error)
+	//注销服务
+	Destory(ctx context.Context, in *ServiceMeta, opts ...grpc.CallOption) (*StringReq, error)
+	//申请服务
+	Apply(ctx context.Context, in *ApplyReqData, opts ...grpc.CallOption) (*ApplyRepData, error)
+	//释放服务
+	Release(ctx context.Context, in *ApplyRepData, opts ...grpc.CallOption) (*StringReq, error)
+}
+
+type serviceClient struct {
+	cc grpc.ClientConnInterface
+}
+
+func NewServiceClient(cc grpc.ClientConnInterface) ServiceClient {
+	return &serviceClient{cc}
+}
+
+func (c *serviceClient) Registe(ctx context.Context, in *ServiceMeta, opts ...grpc.CallOption) (*StringReq, error) {
+	out := new(StringReq)
+	err := c.cc.Invoke(ctx, "/proto.Service/Registe", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *serviceClient) Destory(ctx context.Context, in *ServiceMeta, opts ...grpc.CallOption) (*StringReq, error) {
+	out := new(StringReq)
+	err := c.cc.Invoke(ctx, "/proto.Service/Destory", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *serviceClient) Apply(ctx context.Context, in *ApplyReqData, opts ...grpc.CallOption) (*ApplyRepData, error) {
+	out := new(ApplyRepData)
+	err := c.cc.Invoke(ctx, "/proto.Service/Apply", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *serviceClient) Release(ctx context.Context, in *ApplyRepData, opts ...grpc.CallOption) (*StringReq, error) {
+	out := new(StringReq)
+	err := c.cc.Invoke(ctx, "/proto.Service/Release", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// ServiceServer is the server API for Service service.
+type ServiceServer interface {
+	//注册服务
+	Registe(context.Context, *ServiceMeta) (*StringReq, error)
+	//注销服务
+	Destory(context.Context, *ServiceMeta) (*StringReq, error)
+	//申请服务
+	Apply(context.Context, *ApplyReqData) (*ApplyRepData, error)
+	//释放服务
+	Release(context.Context, *ApplyRepData) (*StringReq, error)
+}
+
+// UnimplementedServiceServer can be embedded to have forward compatible implementations.
+type UnimplementedServiceServer struct {
+}
+
+func (*UnimplementedServiceServer) Registe(ctx context.Context, req *ServiceMeta) (*StringReq, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Registe not implemented")
+}
+func (*UnimplementedServiceServer) Destory(ctx context.Context, req *ServiceMeta) (*StringReq, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Destory not implemented")
+}
+func (*UnimplementedServiceServer) Apply(ctx context.Context, req *ApplyReqData) (*ApplyRepData, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Apply not implemented")
+}
+func (*UnimplementedServiceServer) Release(ctx context.Context, req *ApplyRepData) (*StringReq, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Release not implemented")
+}
+
+func RegisterServiceServer(s *grpc.Server, srv ServiceServer) {
+	s.RegisterService(&_Service_serviceDesc, srv)
+}
+
+func _Service_Registe_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ServiceMeta)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ServiceServer).Registe(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/proto.Service/Registe",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ServiceServer).Registe(ctx, req.(*ServiceMeta))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Service_Destory_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ServiceMeta)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ServiceServer).Destory(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/proto.Service/Destory",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ServiceServer).Destory(ctx, req.(*ServiceMeta))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Service_Apply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ApplyReqData)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ServiceServer).Apply(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/proto.Service/Apply",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ServiceServer).Apply(ctx, req.(*ApplyReqData))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Service_Release_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(ApplyRepData)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ServiceServer).Release(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/proto.Service/Release",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ServiceServer).Release(ctx, req.(*ApplyRepData))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+var _Service_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "proto.Service",
+	HandlerType: (*ServiceServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "Registe",
+			Handler:    _Service_Registe_Handler,
+		},
+		{
+			MethodName: "Destory",
+			Handler:    _Service_Destory_Handler,
+		},
+		{
+			MethodName: "Apply",
+			Handler:    _Service_Apply_Handler,
+		},
+		{
+			MethodName: "Release",
+			Handler:    _Service_Release_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "service.proto",
+}

+ 35 - 0
proto_src/service.proto

@@ -0,0 +1,35 @@
+syntax = "proto3";//声明proto的版本 只能 是3,才支持 grpc
+
+//声明 包名
+package proto;
+
+//服务管理
+service Service {
+  //注册服务
+  rpc Registe(ServiceMeta)returns(StringReq){}
+  //注销服务
+  rpc Destory(ServiceMeta)returns(StringReq){}
+  //申请服务
+  rpc Apply(ApplyReqData)returns(ApplyRepData){}
+  //释放服务
+  rpc Release(ApplyRepData)returns(StringReq){}
+}
+//服务参数
+message ServiceMeta{
+  string serviceName = 1;
+  string serviceAddr = 2;
+  int32 workers = 3;
+  int32 balance = 4;
+}
+//标准字符串返回结果
+message StringReq{
+  string data = 1;
+}
+//
+message ApplyReqData{
+  string serviceName = 1;
+}
+message ApplyRepData{
+  string serviceAddr = 1;
+  string serviceResourceId = 2;
+}