From 2d99a07ba7a2f0a0cc08b979146fdf6d994764b5 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 27 Oct 2021 18:47:36 +0300 Subject: [PATCH] update import paths Signed-off-by: Vasiliy Tolstov --- micro/broker_micro.pb.go | 44 +++- micro/broker_micro_rpc.pb.go | 156 ++++++++++--- proto/broker.pb.go | 437 ++++++++++++++++++++++++++--------- proto/broker.proto | 34 ++- proto/broker_grpc.pb.go | 195 ++++++++++++---- service.go | 45 +++- subscriber.go | 6 +- 7 files changed, 690 insertions(+), 227 deletions(-) diff --git a/micro/broker_micro.pb.go b/micro/broker_micro.pb.go index 2684a8f..2d132fa 100644 --- a/micro/broker_micro.pb.go +++ b/micro/broker_micro.pb.go @@ -12,21 +12,23 @@ import ( ) var ( - BrokerName = "Broker" + BrokerServiceName = "BrokerService" - BrokerEndpoints = []api.Endpoint{} + BrokerServiceEndpoints = []api.Endpoint{} ) -func NewBrokerEndpoints() []api.Endpoint { - return BrokerEndpoints +func NewBrokerServiceEndpoints() []api.Endpoint { + return BrokerServiceEndpoints } -type BrokerClient interface { - Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.Empty, error) - Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeClient, error) +type BrokerServiceClient interface { + Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error) + BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, opts ...client.CallOption) (*proto.BatchPublishResponse, error) + Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (BrokerService_SubscribeClient, error) + BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, opts ...client.CallOption) (BrokerService_BatchSubscribeClient, error) } -type Broker_SubscribeClient interface { +type BrokerService_SubscribeClient interface { Context() context.Context SendMsg(msg interface{}) error RecvMsg(msg interface{}) error @@ -34,12 +36,30 @@ type Broker_SubscribeClient interface { Recv() (*proto.Message, error) } -type BrokerServer interface { - Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.Empty) error - Subscribe(ctx context.Context, req *proto.SubscribeRequest, stream Broker_SubscribeStream) error +type BrokerService_BatchSubscribeClient interface { + Context() context.Context + SendMsg(msg interface{}) error + RecvMsg(msg interface{}) error + Close() error + Recv() (*proto.Message, error) } -type Broker_SubscribeStream interface { +type BrokerServiceServer interface { + Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error + BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error + Subscribe(ctx context.Context, req *proto.SubscribeRequest, stream BrokerService_SubscribeStream) error + BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, stream BrokerService_BatchSubscribeStream) error +} + +type BrokerService_SubscribeStream interface { + Context() context.Context + SendMsg(msg interface{}) error + RecvMsg(msg interface{}) error + Close() error + Send(msg *proto.Message) error +} + +type BrokerService_BatchSubscribeStream interface { Context() context.Context SendMsg(msg interface{}) error RecvMsg(msg interface{}) error diff --git a/micro/broker_micro_rpc.pb.go b/micro/broker_micro_rpc.pb.go index b6a8f38..9227a91 100644 --- a/micro/broker_micro_rpc.pb.go +++ b/micro/broker_micro_rpc.pb.go @@ -12,56 +12,65 @@ import ( server "go.unistack.org/micro/v3/server" ) -type brokerClient struct { +type brokerServiceClient struct { c client.Client name string } -func NewBrokerClient(name string, c client.Client) BrokerClient { - return &brokerClient{c: c, name: name} +func NewBrokerServiceClient(name string, c client.Client) BrokerServiceClient { + return &brokerServiceClient{c: c, name: name} } -func (c *brokerClient) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.Empty, error) { - rsp := &proto.Empty{} - err := c.c.Call(ctx, c.c.NewRequest(c.name, "Broker.Publish", req), rsp, opts...) +func (c *brokerServiceClient) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error) { + rsp := &proto.PublishResponse{} + err := c.c.Call(ctx, c.c.NewRequest(c.name, "BrokerService.Publish", req), rsp, opts...) if err != nil { return nil, err } return rsp, nil } -func (c *brokerClient) Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeClient, error) { - stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Broker.Subscribe", &proto.SubscribeRequest{}), opts...) +func (c *brokerServiceClient) BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, opts ...client.CallOption) (*proto.BatchPublishResponse, error) { + rsp := &proto.BatchPublishResponse{} + err := c.c.Call(ctx, c.c.NewRequest(c.name, "BrokerService.BatchPublish", req), rsp, opts...) + if err != nil { + return nil, err + } + return rsp, nil +} + +func (c *brokerServiceClient) Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (BrokerService_SubscribeClient, error) { + stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "BrokerService.Subscribe", &proto.SubscribeRequest{}), opts...) if err != nil { return nil, err } if err := stream.Send(req); err != nil { return nil, err } - return &brokerClientSubscribe{stream}, nil + return &brokerServiceClientSubscribe{stream}, nil } -type brokerClientSubscribe struct { +type brokerServiceClientSubscribe struct { stream client.Stream } -func (s *brokerClientSubscribe) Close() error { +func (s *brokerServiceClientSubscribe) Close() error { return s.stream.Close() } -func (s *brokerClientSubscribe) Context() context.Context { +func (s *brokerServiceClientSubscribe) Context() context.Context { return s.stream.Context() } -func (s *brokerClientSubscribe) SendMsg(msg interface{}) error { +func (s *brokerServiceClientSubscribe) SendMsg(msg interface{}) error { return s.stream.Send(msg) } -func (s *brokerClientSubscribe) RecvMsg(msg interface{}) error { +func (s *brokerServiceClientSubscribe) RecvMsg(msg interface{}) error { return s.stream.Recv(msg) } -func (s *brokerClientSubscribe) Recv() (*proto.Message, error) { +func (s *brokerServiceClientSubscribe) Recv() (*proto.Message, error) { msg := &proto.Message{} if err := s.stream.Recv(msg); err != nil { return nil, err @@ -69,58 +78,135 @@ func (s *brokerClientSubscribe) Recv() (*proto.Message, error) { return msg, nil } -type brokerServer struct { - BrokerServer +func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, opts ...client.CallOption) (BrokerService_BatchSubscribeClient, error) { + stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "BrokerService.BatchSubscribe", &proto.BatchSubscribeRequest{}), opts...) + if err != nil { + return nil, err + } + if err := stream.Send(req); err != nil { + return nil, err + } + return &brokerServiceClientBatchSubscribe{stream}, nil } -func (h *brokerServer) Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.Empty) error { - return h.BrokerServer.Publish(ctx, req, rsp) +type brokerServiceClientBatchSubscribe struct { + stream client.Stream } -func (h *brokerServer) Subscribe(ctx context.Context, stream server.Stream) error { +func (s *brokerServiceClientBatchSubscribe) Close() error { + return s.stream.Close() +} + +func (s *brokerServiceClientBatchSubscribe) Context() context.Context { + return s.stream.Context() +} + +func (s *brokerServiceClientBatchSubscribe) SendMsg(msg interface{}) error { + return s.stream.Send(msg) +} + +func (s *brokerServiceClientBatchSubscribe) RecvMsg(msg interface{}) error { + return s.stream.Recv(msg) +} + +func (s *brokerServiceClientBatchSubscribe) Recv() (*proto.Message, error) { + msg := &proto.Message{} + if err := s.stream.Recv(msg); err != nil { + return nil, err + } + return msg, nil +} + +type brokerServiceServer struct { + BrokerServiceServer +} + +func (h *brokerServiceServer) Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error { + return h.BrokerServiceServer.Publish(ctx, req, rsp) +} + +func (h *brokerServiceServer) BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error { + return h.BrokerServiceServer.BatchPublish(ctx, req, rsp) +} + +func (h *brokerServiceServer) Subscribe(ctx context.Context, stream server.Stream) error { msg := &proto.SubscribeRequest{} if err := stream.Recv(msg); err != nil { return err } - return h.BrokerServer.Subscribe(ctx, msg, &brokerSubscribeStream{stream}) + return h.BrokerServiceServer.Subscribe(ctx, msg, &brokerServiceSubscribeStream{stream}) } -type brokerSubscribeStream struct { +type brokerServiceSubscribeStream struct { stream server.Stream } -func (s *brokerSubscribeStream) Close() error { +func (s *brokerServiceSubscribeStream) Close() error { return s.stream.Close() } -func (s *brokerSubscribeStream) Context() context.Context { +func (s *brokerServiceSubscribeStream) Context() context.Context { return s.stream.Context() } -func (s *brokerSubscribeStream) SendMsg(msg interface{}) error { +func (s *brokerServiceSubscribeStream) SendMsg(msg interface{}) error { return s.stream.Send(msg) } -func (s *brokerSubscribeStream) RecvMsg(msg interface{}) error { +func (s *brokerServiceSubscribeStream) RecvMsg(msg interface{}) error { return s.stream.Recv(msg) } -func (s *brokerSubscribeStream) Send(msg *proto.Message) error { +func (s *brokerServiceSubscribeStream) Send(msg *proto.Message) error { return s.stream.Send(msg) } -func RegisterBrokerServer(s server.Server, sh BrokerServer, opts ...server.HandlerOption) error { - type broker interface { - Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.Empty) error +func (h *brokerServiceServer) BatchSubscribe(ctx context.Context, stream server.Stream) error { + msg := &proto.BatchSubscribeRequest{} + if err := stream.Recv(msg); err != nil { + return err + } + return h.BrokerServiceServer.BatchSubscribe(ctx, msg, &brokerServiceBatchSubscribeStream{stream}) +} + +type brokerServiceBatchSubscribeStream struct { + stream server.Stream +} + +func (s *brokerServiceBatchSubscribeStream) Close() error { + return s.stream.Close() +} + +func (s *brokerServiceBatchSubscribeStream) Context() context.Context { + return s.stream.Context() +} + +func (s *brokerServiceBatchSubscribeStream) SendMsg(msg interface{}) error { + return s.stream.Send(msg) +} + +func (s *brokerServiceBatchSubscribeStream) RecvMsg(msg interface{}) error { + return s.stream.Recv(msg) +} + +func (s *brokerServiceBatchSubscribeStream) Send(msg *proto.Message) error { + return s.stream.Send(msg) +} + +func RegisterBrokerServiceServer(s server.Server, sh BrokerServiceServer, opts ...server.HandlerOption) error { + type brokerService interface { + Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.PublishResponse) error + BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, rsp *proto.BatchPublishResponse) error Subscribe(ctx context.Context, stream server.Stream) error + BatchSubscribe(ctx context.Context, stream server.Stream) error } - type Broker struct { - broker + type BrokerService struct { + brokerService } - h := &brokerServer{sh} + h := &brokerServiceServer{sh} var nopts []server.HandlerOption - for _, endpoint := range BrokerEndpoints { + for _, endpoint := range BrokerServiceEndpoints { nopts = append(nopts, api.WithEndpoint(&endpoint)) } - return s.Handle(s.NewHandler(&Broker{h}, append(nopts, opts...)...)) + return s.Handle(s.NewHandler(&BrokerService{h}, append(nopts, opts...)...)) } diff --git a/proto/broker.pb.go b/proto/broker.pb.go index 27a207c..a4465da 100644 --- a/proto/broker.pb.go +++ b/proto/broker.pb.go @@ -20,44 +20,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -type Empty struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *Empty) Reset() { - *x = Empty{} - if protoimpl.UnsafeEnabled { - mi := &file_broker_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Empty) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Empty) ProtoMessage() {} - -func (x *Empty) ProtoReflect() protoreflect.Message { - mi := &file_broker_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 Empty.ProtoReflect.Descriptor instead. -func (*Empty) Descriptor() ([]byte, []int) { - return file_broker_proto_rawDescGZIP(), []int{0} -} - type PublishRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -70,7 +32,7 @@ type PublishRequest struct { func (x *PublishRequest) Reset() { *x = PublishRequest{} if protoimpl.UnsafeEnabled { - mi := &file_broker_proto_msgTypes[1] + mi := &file_broker_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -83,7 +45,7 @@ func (x *PublishRequest) String() string { func (*PublishRequest) ProtoMessage() {} func (x *PublishRequest) ProtoReflect() protoreflect.Message { - mi := &file_broker_proto_msgTypes[1] + mi := &file_broker_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -96,7 +58,7 @@ func (x *PublishRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead. func (*PublishRequest) Descriptor() ([]byte, []int) { - return file_broker_proto_rawDescGZIP(), []int{1} + return file_broker_proto_rawDescGZIP(), []int{0} } func (x *PublishRequest) GetTopic() string { @@ -113,6 +75,137 @@ func (x *PublishRequest) GetMessage() *Message { return nil } +type BatchPublishRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"` + Message []*Message `protobuf:"bytes,2,rep,name=message,proto3" json:"message,omitempty"` +} + +func (x *BatchPublishRequest) Reset() { + *x = BatchPublishRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_broker_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BatchPublishRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BatchPublishRequest) ProtoMessage() {} + +func (x *BatchPublishRequest) ProtoReflect() protoreflect.Message { + mi := &file_broker_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 BatchPublishRequest.ProtoReflect.Descriptor instead. +func (*BatchPublishRequest) Descriptor() ([]byte, []int) { + return file_broker_proto_rawDescGZIP(), []int{1} +} + +func (x *BatchPublishRequest) GetTopic() string { + if x != nil { + return x.Topic + } + return "" +} + +func (x *BatchPublishRequest) GetMessage() []*Message { + if x != nil { + return x.Message + } + return nil +} + +type PublishResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *PublishResponse) Reset() { + *x = PublishResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_broker_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PublishResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PublishResponse) ProtoMessage() {} + +func (x *PublishResponse) ProtoReflect() protoreflect.Message { + mi := &file_broker_proto_msgTypes[2] + 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 PublishResponse.ProtoReflect.Descriptor instead. +func (*PublishResponse) Descriptor() ([]byte, []int) { + return file_broker_proto_rawDescGZIP(), []int{2} +} + +type BatchPublishResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *BatchPublishResponse) Reset() { + *x = BatchPublishResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_broker_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BatchPublishResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BatchPublishResponse) ProtoMessage() {} + +func (x *BatchPublishResponse) ProtoReflect() protoreflect.Message { + mi := &file_broker_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 BatchPublishResponse.ProtoReflect.Descriptor instead. +func (*BatchPublishResponse) Descriptor() ([]byte, []int) { + return file_broker_proto_rawDescGZIP(), []int{3} +} + type SubscribeRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -125,7 +218,7 @@ type SubscribeRequest struct { func (x *SubscribeRequest) Reset() { *x = SubscribeRequest{} if protoimpl.UnsafeEnabled { - mi := &file_broker_proto_msgTypes[2] + mi := &file_broker_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -138,7 +231,7 @@ func (x *SubscribeRequest) String() string { func (*SubscribeRequest) ProtoMessage() {} func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { - mi := &file_broker_proto_msgTypes[2] + mi := &file_broker_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -151,7 +244,7 @@ func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead. func (*SubscribeRequest) Descriptor() ([]byte, []int) { - return file_broker_proto_rawDescGZIP(), []int{2} + return file_broker_proto_rawDescGZIP(), []int{4} } func (x *SubscribeRequest) GetTopic() string { @@ -168,6 +261,61 @@ func (x *SubscribeRequest) GetGroup() string { return "" } +type BatchSubscribeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Topic string `protobuf:"bytes,1,opt,name=topic,proto3" json:"topic,omitempty"` + Group string `protobuf:"bytes,2,opt,name=group,proto3" json:"group,omitempty"` +} + +func (x *BatchSubscribeRequest) Reset() { + *x = BatchSubscribeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_broker_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BatchSubscribeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BatchSubscribeRequest) ProtoMessage() {} + +func (x *BatchSubscribeRequest) ProtoReflect() protoreflect.Message { + mi := &file_broker_proto_msgTypes[5] + 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 BatchSubscribeRequest.ProtoReflect.Descriptor instead. +func (*BatchSubscribeRequest) Descriptor() ([]byte, []int) { + return file_broker_proto_rawDescGZIP(), []int{5} +} + +func (x *BatchSubscribeRequest) GetTopic() string { + if x != nil { + return x.Topic + } + return "" +} + +func (x *BatchSubscribeRequest) GetGroup() string { + if x != nil { + return x.Group + } + return "" +} + type Message struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -180,7 +328,7 @@ type Message struct { func (x *Message) Reset() { *x = Message{} if protoimpl.UnsafeEnabled { - mi := &file_broker_proto_msgTypes[3] + mi := &file_broker_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -193,7 +341,7 @@ func (x *Message) String() string { func (*Message) ProtoMessage() {} func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_broker_proto_msgTypes[3] + mi := &file_broker_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -206,7 +354,7 @@ func (x *Message) ProtoReflect() protoreflect.Message { // Deprecated: Use Message.ProtoReflect.Descriptor instead. func (*Message) Descriptor() ([]byte, []int) { - return file_broker_proto_rawDescGZIP(), []int{3} + return file_broker_proto_rawDescGZIP(), []int{6} } func (x *Message) GetHeader() map[string]string { @@ -227,39 +375,62 @@ var File_broker_proto protoreflect.FileDescriptor var file_broker_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, - 0x74, 0x79, 0x22, 0x54, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, - 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, - 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3e, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, - 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, - 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, - 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, - 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, - 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 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, 0x32, 0x84, 0x01, 0x0a, 0x06, - 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x12, 0x38, 0x0a, 0x07, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x50, 0x75, - 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x73, - 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, - 0x12, 0x40, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x1b, 0x2e, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, - 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, - 0x30, 0x01, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, - 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x62, 0x72, 0x6f, 0x6b, - 0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x22, 0x54, 0x0a, 0x0e, 0x50, 0x75, 0x62, + 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, + 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, + 0x63, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, + 0x59, 0x0a, 0x13, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x07, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75, + 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x0a, + 0x14, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3e, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, + 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, + 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x43, 0x0a, 0x15, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75, + 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, + 0x6f, 0x70, 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, + 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, + 0x64, 0x79, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 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, 0x32, 0xb4, 0x02, + 0x0a, 0x0d, 0x42, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x42, 0x0a, 0x07, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, + 0x62, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x0c, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, + 0x69, 0x73, 0x68, 0x12, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, + 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, + 0x69, 0x62, 0x65, 0x12, 0x1b, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, + 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x30, 0x01, 0x12, 0x4a, 0x0a, 0x0e, 0x42, 0x61, 0x74, 0x63, + 0x68, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x20, 0x2e, 0x73, 0x65, 0x72, + 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75, 0x62, 0x73, + 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x22, 0x00, 0x30, 0x01, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, + 0x61, 0x63, 0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x62, 0x72, + 0x6f, 0x6b, 0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -274,26 +445,34 @@ func file_broker_proto_rawDescGZIP() []byte { return file_broker_proto_rawDescData } -var file_broker_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_broker_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_broker_proto_goTypes = []interface{}{ - (*Empty)(nil), // 0: servicepb.Empty - (*PublishRequest)(nil), // 1: servicepb.PublishRequest - (*SubscribeRequest)(nil), // 2: servicepb.SubscribeRequest - (*Message)(nil), // 3: servicepb.Message - nil, // 4: servicepb.Message.HeaderEntry + (*PublishRequest)(nil), // 0: servicepb.PublishRequest + (*BatchPublishRequest)(nil), // 1: servicepb.BatchPublishRequest + (*PublishResponse)(nil), // 2: servicepb.PublishResponse + (*BatchPublishResponse)(nil), // 3: servicepb.BatchPublishResponse + (*SubscribeRequest)(nil), // 4: servicepb.SubscribeRequest + (*BatchSubscribeRequest)(nil), // 5: servicepb.BatchSubscribeRequest + (*Message)(nil), // 6: servicepb.Message + nil, // 7: servicepb.Message.HeaderEntry } var file_broker_proto_depIdxs = []int32{ - 3, // 0: servicepb.PublishRequest.message:type_name -> servicepb.Message - 4, // 1: servicepb.Message.header:type_name -> servicepb.Message.HeaderEntry - 1, // 2: servicepb.Broker.Publish:input_type -> servicepb.PublishRequest - 2, // 3: servicepb.Broker.Subscribe:input_type -> servicepb.SubscribeRequest - 0, // 4: servicepb.Broker.Publish:output_type -> servicepb.Empty - 3, // 5: servicepb.Broker.Subscribe:output_type -> servicepb.Message - 4, // [4:6] is the sub-list for method output_type - 2, // [2:4] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 6, // 0: servicepb.PublishRequest.message:type_name -> servicepb.Message + 6, // 1: servicepb.BatchPublishRequest.message:type_name -> servicepb.Message + 7, // 2: servicepb.Message.header:type_name -> servicepb.Message.HeaderEntry + 0, // 3: servicepb.BrokerService.Publish:input_type -> servicepb.PublishRequest + 1, // 4: servicepb.BrokerService.BatchPublish:input_type -> servicepb.BatchPublishRequest + 4, // 5: servicepb.BrokerService.Subscribe:input_type -> servicepb.SubscribeRequest + 5, // 6: servicepb.BrokerService.BatchSubscribe:input_type -> servicepb.BatchSubscribeRequest + 2, // 7: servicepb.BrokerService.Publish:output_type -> servicepb.PublishResponse + 3, // 8: servicepb.BrokerService.BatchPublish:output_type -> servicepb.BatchPublishResponse + 6, // 9: servicepb.BrokerService.Subscribe:output_type -> servicepb.Message + 6, // 10: servicepb.BrokerService.BatchSubscribe:output_type -> servicepb.Message + 7, // [7:11] is the sub-list for method output_type + 3, // [3:7] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_broker_proto_init() } @@ -303,18 +482,6 @@ func file_broker_proto_init() { } if !protoimpl.UnsafeEnabled { file_broker_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Empty); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_broker_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PublishRequest); i { case 0: return &v.state @@ -326,8 +493,20 @@ func file_broker_proto_init() { return nil } } + file_broker_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchPublishRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } file_broker_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SubscribeRequest); i { + switch v := v.(*PublishResponse); i { case 0: return &v.state case 1: @@ -339,6 +518,42 @@ func file_broker_proto_init() { } } file_broker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchPublishResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broker_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SubscribeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broker_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BatchSubscribeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_broker_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Message); i { case 0: return &v.state @@ -357,7 +572,7 @@ func file_broker_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_broker_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/broker.proto b/proto/broker.proto index 9ad8ed8..891975f 100644 --- a/proto/broker.proto +++ b/proto/broker.proto @@ -3,24 +3,42 @@ syntax = "proto3"; package servicepb; option go_package="go.unistack.org/micro-broker-service/v3/proto;servicepb"; -service Broker { - rpc Publish(PublishRequest) returns (Empty) {}; +service BrokerService { + rpc Publish(PublishRequest) returns (PublishResponse) {}; + rpc BatchPublish(BatchPublishRequest) returns (BatchPublishResponse) {}; rpc Subscribe(SubscribeRequest) returns (stream Message) {}; -} - -message Empty {} + rpc BatchSubscribe(BatchSubscribeRequest) returns (stream Message) {}; +}; message PublishRequest { string topic = 1; Message message = 2; -} +}; + +message BatchPublishRequest { + string topic = 1; + repeated Message message = 2; +}; + +message PublishResponse { + +}; + +message BatchPublishResponse { + +}; message SubscribeRequest { string topic = 1; string group = 2; -} +}; + +message BatchSubscribeRequest { + string topic = 1; + string group = 2; +}; message Message { map header = 1; bytes body = 2; -} +}; diff --git a/proto/broker_grpc.pb.go b/proto/broker_grpc.pb.go index 4a6e3b7..7f7614b 100644 --- a/proto/broker_grpc.pb.go +++ b/proto/broker_grpc.pb.go @@ -14,37 +14,48 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 -// BrokerClient is the client API for Broker service. +// BrokerServiceClient is the client API for BrokerService service. // // 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 BrokerClient interface { - Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) - Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, error) +type BrokerServiceClient interface { + Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error) + BatchPublish(ctx context.Context, in *BatchPublishRequest, opts ...grpc.CallOption) (*BatchPublishResponse, error) + Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (BrokerService_SubscribeClient, error) + BatchSubscribe(ctx context.Context, in *BatchSubscribeRequest, opts ...grpc.CallOption) (BrokerService_BatchSubscribeClient, error) } -type brokerClient struct { +type brokerServiceClient struct { cc grpc.ClientConnInterface } -func NewBrokerClient(cc grpc.ClientConnInterface) BrokerClient { - return &brokerClient{cc} +func NewBrokerServiceClient(cc grpc.ClientConnInterface) BrokerServiceClient { + return &brokerServiceClient{cc} } -func (c *brokerClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) { - out := new(Empty) - err := c.cc.Invoke(ctx, "/servicepb.Broker/Publish", in, out, opts...) +func (c *brokerServiceClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error) { + out := new(PublishResponse) + err := c.cc.Invoke(ctx, "/servicepb.BrokerService/Publish", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *brokerClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, error) { - stream, err := c.cc.NewStream(ctx, &Broker_ServiceDesc.Streams[0], "/servicepb.Broker/Subscribe", opts...) +func (c *brokerServiceClient) BatchPublish(ctx context.Context, in *BatchPublishRequest, opts ...grpc.CallOption) (*BatchPublishResponse, error) { + out := new(BatchPublishResponse) + err := c.cc.Invoke(ctx, "/servicepb.BrokerService/BatchPublish", in, out, opts...) if err != nil { return nil, err } - x := &brokerSubscribeClient{stream} + return out, nil +} + +func (c *brokerServiceClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (BrokerService_SubscribeClient, error) { + stream, err := c.cc.NewStream(ctx, &BrokerService_ServiceDesc.Streams[0], "/servicepb.BrokerService/Subscribe", opts...) + if err != nil { + return nil, err + } + x := &brokerServiceSubscribeClient{stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } @@ -54,16 +65,16 @@ func (c *brokerClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts return x, nil } -type Broker_SubscribeClient interface { +type BrokerService_SubscribeClient interface { Recv() (*Message, error) grpc.ClientStream } -type brokerSubscribeClient struct { +type brokerServiceSubscribeClient struct { grpc.ClientStream } -func (x *brokerSubscribeClient) Recv() (*Message, error) { +func (x *brokerServiceSubscribeClient) Recv() (*Message, error) { m := new(Message) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err @@ -71,93 +82,181 @@ func (x *brokerSubscribeClient) Recv() (*Message, error) { return m, nil } -// BrokerServer is the server API for Broker service. -// All implementations must embed UnimplementedBrokerServer +func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, in *BatchSubscribeRequest, opts ...grpc.CallOption) (BrokerService_BatchSubscribeClient, error) { + stream, err := c.cc.NewStream(ctx, &BrokerService_ServiceDesc.Streams[1], "/servicepb.BrokerService/BatchSubscribe", opts...) + if err != nil { + return nil, err + } + x := &brokerServiceBatchSubscribeClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type BrokerService_BatchSubscribeClient interface { + Recv() (*Message, error) + grpc.ClientStream +} + +type brokerServiceBatchSubscribeClient struct { + grpc.ClientStream +} + +func (x *brokerServiceBatchSubscribeClient) Recv() (*Message, error) { + m := new(Message) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// BrokerServiceServer is the server API for BrokerService service. +// All implementations must embed UnimplementedBrokerServiceServer // for forward compatibility -type BrokerServer interface { - Publish(context.Context, *PublishRequest) (*Empty, error) - Subscribe(*SubscribeRequest, Broker_SubscribeServer) error - mustEmbedUnimplementedBrokerServer() +type BrokerServiceServer interface { + Publish(context.Context, *PublishRequest) (*PublishResponse, error) + BatchPublish(context.Context, *BatchPublishRequest) (*BatchPublishResponse, error) + Subscribe(*SubscribeRequest, BrokerService_SubscribeServer) error + BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error + mustEmbedUnimplementedBrokerServiceServer() } -// UnimplementedBrokerServer must be embedded to have forward compatible implementations. -type UnimplementedBrokerServer struct { +// UnimplementedBrokerServiceServer must be embedded to have forward compatible implementations. +type UnimplementedBrokerServiceServer struct { } -func (UnimplementedBrokerServer) Publish(context.Context, *PublishRequest) (*Empty, error) { +func (UnimplementedBrokerServiceServer) Publish(context.Context, *PublishRequest) (*PublishResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented") } -func (UnimplementedBrokerServer) Subscribe(*SubscribeRequest, Broker_SubscribeServer) error { +func (UnimplementedBrokerServiceServer) BatchPublish(context.Context, *BatchPublishRequest) (*BatchPublishResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BatchPublish not implemented") +} +func (UnimplementedBrokerServiceServer) Subscribe(*SubscribeRequest, BrokerService_SubscribeServer) error { return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") } -func (UnimplementedBrokerServer) mustEmbedUnimplementedBrokerServer() {} +func (UnimplementedBrokerServiceServer) BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error { + return status.Errorf(codes.Unimplemented, "method BatchSubscribe not implemented") +} +func (UnimplementedBrokerServiceServer) mustEmbedUnimplementedBrokerServiceServer() {} -// UnsafeBrokerServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to BrokerServer will +// UnsafeBrokerServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BrokerServiceServer will // result in compilation errors. -type UnsafeBrokerServer interface { - mustEmbedUnimplementedBrokerServer() +type UnsafeBrokerServiceServer interface { + mustEmbedUnimplementedBrokerServiceServer() } -func RegisterBrokerServer(s grpc.ServiceRegistrar, srv BrokerServer) { - s.RegisterService(&Broker_ServiceDesc, srv) +func RegisterBrokerServiceServer(s grpc.ServiceRegistrar, srv BrokerServiceServer) { + s.RegisterService(&BrokerService_ServiceDesc, srv) } -func _Broker_Publish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _BrokerService_Publish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(PublishRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(BrokerServer).Publish(ctx, in) + return srv.(BrokerServiceServer).Publish(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/servicepb.Broker/Publish", + FullMethod: "/servicepb.BrokerService/Publish", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(BrokerServer).Publish(ctx, req.(*PublishRequest)) + return srv.(BrokerServiceServer).Publish(ctx, req.(*PublishRequest)) } return interceptor(ctx, in, info, handler) } -func _Broker_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error { +func _BrokerService_BatchPublish_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BatchPublishRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BrokerServiceServer).BatchPublish(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/servicepb.BrokerService/BatchPublish", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BrokerServiceServer).BatchPublish(ctx, req.(*BatchPublishRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _BrokerService_Subscribe_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(SubscribeRequest) if err := stream.RecvMsg(m); err != nil { return err } - return srv.(BrokerServer).Subscribe(m, &brokerSubscribeServer{stream}) + return srv.(BrokerServiceServer).Subscribe(m, &brokerServiceSubscribeServer{stream}) } -type Broker_SubscribeServer interface { +type BrokerService_SubscribeServer interface { Send(*Message) error grpc.ServerStream } -type brokerSubscribeServer struct { +type brokerServiceSubscribeServer struct { grpc.ServerStream } -func (x *brokerSubscribeServer) Send(m *Message) error { +func (x *brokerServiceSubscribeServer) Send(m *Message) error { return x.ServerStream.SendMsg(m) } -// Broker_ServiceDesc is the grpc.ServiceDesc for Broker service. +func _BrokerService_BatchSubscribe_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(BatchSubscribeRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(BrokerServiceServer).BatchSubscribe(m, &brokerServiceBatchSubscribeServer{stream}) +} + +type BrokerService_BatchSubscribeServer interface { + Send(*Message) error + grpc.ServerStream +} + +type brokerServiceBatchSubscribeServer struct { + grpc.ServerStream +} + +func (x *brokerServiceBatchSubscribeServer) Send(m *Message) error { + return x.ServerStream.SendMsg(m) +} + +// BrokerService_ServiceDesc is the grpc.ServiceDesc for BrokerService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) -var Broker_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "servicepb.Broker", - HandlerType: (*BrokerServer)(nil), +var BrokerService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "servicepb.BrokerService", + HandlerType: (*BrokerServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Publish", - Handler: _Broker_Publish_Handler, + Handler: _BrokerService_Publish_Handler, + }, + { + MethodName: "BatchPublish", + Handler: _BrokerService_BatchPublish_Handler, }, }, Streams: []grpc.StreamDesc{ { StreamName: "Subscribe", - Handler: _Broker_Subscribe_Handler, + Handler: _BrokerService_Subscribe_Handler, + ServerStreams: true, + }, + { + StreamName: "BatchSubscribe", + Handler: _BrokerService_BatchSubscribe_Handler, ServerStreams: true, }, }, diff --git a/service.go b/service.go index 8835e86..f9ae7b1 100644 --- a/service.go +++ b/service.go @@ -11,12 +11,13 @@ import ( "go.unistack.org/micro/v3/broker" "go.unistack.org/micro/v3/client" "go.unistack.org/micro/v3/logger" + "go.unistack.org/micro/v3/metadata" ) type serviceBroker struct { addrs []string service string - client pbmicro.BrokerClient + client pbmicro.BrokerServiceClient init bool opts broker.Options } @@ -73,7 +74,7 @@ func (b *serviceBroker) Init(opts ...broker.Option) error { return fmt.Errorf("missing Client option") } - b.client = pbmicro.NewBrokerClient(b.service, cli) + b.client = pbmicro.NewBrokerServiceClient(b.service, cli) b.init = true return nil @@ -83,18 +84,38 @@ func (b *serviceBroker) Options() broker.Options { return b.opts } +func (b *serviceBroker) BatchPublish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error { + return b.publish(ctx, msgs, opts...) +} + func (b *serviceBroker) Publish(ctx context.Context, topic string, msg *broker.Message, opts ...broker.PublishOption) error { - if logger.V(logger.TraceLevel) { - logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs) + msg.Header.Set(metadata.HeaderTopic, topic) + return b.publish(ctx, []*broker.Message{msg}, opts...) +} + +func (b *serviceBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error { + for _, msg := range msgs { + topic, _ := msg.Header.Get(metadata.HeaderTopic) + if logger.V(logger.TraceLevel) { + logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs) + } + _, err := b.client.Publish(ctx, &pb.PublishRequest{ + Topic: topic, + Message: &pb.Message{ + Header: msg.Header, + Body: msg.Body, + }, + }, client.WithAddress(b.addrs...)) + if err != nil { + return err + } } - _, err := b.client.Publish(ctx, &pb.PublishRequest{ - Topic: topic, - Message: &pb.Message{ - Header: msg.Header, - Body: msg.Body, - }, - }, client.WithAddress(b.addrs...)) - return err + + return nil +} + +func (b *serviceBroker) BatchSubscribe(ctx context.Context, topic string, handler broker.BatchHandler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { + return nil, nil } func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { diff --git a/subscriber.go b/subscriber.go index e0e146f..8fc47c9 100644 --- a/subscriber.go +++ b/subscriber.go @@ -12,7 +12,7 @@ type serviceSub struct { topic string group string handler broker.Handler - stream pbmicro.Broker_SubscribeClient + stream pbmicro.BrokerService_SubscribeClient closed chan bool options broker.SubscribeOptions } @@ -39,6 +39,10 @@ func (s *serviceEvent) Error() error { return s.err } +func (s *serviceEvent) SetError(err error) { + s.err = err +} + func (s *serviceSub) isClosed() bool { select { case <-s.closed: