update import paths

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-10-27 18:47:36 +03:00
parent e5ea846039
commit 2d99a07ba7
7 changed files with 690 additions and 227 deletions

View File

@ -12,21 +12,23 @@ import (
) )
var ( var (
BrokerName = "Broker" BrokerServiceName = "BrokerService"
BrokerEndpoints = []api.Endpoint{} BrokerServiceEndpoints = []api.Endpoint{}
) )
func NewBrokerEndpoints() []api.Endpoint { func NewBrokerServiceEndpoints() []api.Endpoint {
return BrokerEndpoints return BrokerServiceEndpoints
} }
type BrokerClient interface { type BrokerServiceClient interface {
Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.Empty, error) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error)
Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeClient, 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 Context() context.Context
SendMsg(msg interface{}) error SendMsg(msg interface{}) error
RecvMsg(msg interface{}) error RecvMsg(msg interface{}) error
@ -34,12 +36,30 @@ type Broker_SubscribeClient interface {
Recv() (*proto.Message, error) Recv() (*proto.Message, error)
} }
type BrokerServer interface { type BrokerService_BatchSubscribeClient interface {
Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.Empty) error Context() context.Context
Subscribe(ctx context.Context, req *proto.SubscribeRequest, stream Broker_SubscribeStream) error 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 Context() context.Context
SendMsg(msg interface{}) error SendMsg(msg interface{}) error
RecvMsg(msg interface{}) error RecvMsg(msg interface{}) error

View File

@ -12,56 +12,65 @@ import (
server "go.unistack.org/micro/v3/server" server "go.unistack.org/micro/v3/server"
) )
type brokerClient struct { type brokerServiceClient struct {
c client.Client c client.Client
name string name string
} }
func NewBrokerClient(name string, c client.Client) BrokerClient { func NewBrokerServiceClient(name string, c client.Client) BrokerServiceClient {
return &brokerClient{c: c, name: name} return &brokerServiceClient{c: c, name: name}
} }
func (c *brokerClient) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.Empty, error) { func (c *brokerServiceClient) Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error) {
rsp := &proto.Empty{} rsp := &proto.PublishResponse{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Broker.Publish", req), rsp, opts...) err := c.c.Call(ctx, c.c.NewRequest(c.name, "BrokerService.Publish", req), rsp, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return rsp, nil return rsp, nil
} }
func (c *brokerClient) Subscribe(ctx context.Context, req *proto.SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeClient, error) { func (c *brokerServiceClient) BatchPublish(ctx context.Context, req *proto.BatchPublishRequest, opts ...client.CallOption) (*proto.BatchPublishResponse, error) {
stream, err := c.c.Stream(ctx, c.c.NewRequest(c.name, "Broker.Subscribe", &proto.SubscribeRequest{}), opts...) 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 { if err != nil {
return nil, err return nil, err
} }
if err := stream.Send(req); err != nil { if err := stream.Send(req); err != nil {
return nil, err return nil, err
} }
return &brokerClientSubscribe{stream}, nil return &brokerServiceClientSubscribe{stream}, nil
} }
type brokerClientSubscribe struct { type brokerServiceClientSubscribe struct {
stream client.Stream stream client.Stream
} }
func (s *brokerClientSubscribe) Close() error { func (s *brokerServiceClientSubscribe) Close() error {
return s.stream.Close() return s.stream.Close()
} }
func (s *brokerClientSubscribe) Context() context.Context { func (s *brokerServiceClientSubscribe) Context() context.Context {
return s.stream.Context() return s.stream.Context()
} }
func (s *brokerClientSubscribe) SendMsg(msg interface{}) error { func (s *brokerServiceClientSubscribe) SendMsg(msg interface{}) error {
return s.stream.Send(msg) return s.stream.Send(msg)
} }
func (s *brokerClientSubscribe) RecvMsg(msg interface{}) error { func (s *brokerServiceClientSubscribe) RecvMsg(msg interface{}) error {
return s.stream.Recv(msg) return s.stream.Recv(msg)
} }
func (s *brokerClientSubscribe) Recv() (*proto.Message, error) { func (s *brokerServiceClientSubscribe) Recv() (*proto.Message, error) {
msg := &proto.Message{} msg := &proto.Message{}
if err := s.stream.Recv(msg); err != nil { if err := s.stream.Recv(msg); err != nil {
return nil, err return nil, err
@ -69,58 +78,135 @@ func (s *brokerClientSubscribe) Recv() (*proto.Message, error) {
return msg, nil return msg, nil
} }
type brokerServer struct { func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, req *proto.BatchSubscribeRequest, opts ...client.CallOption) (BrokerService_BatchSubscribeClient, error) {
BrokerServer 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 { type brokerServiceClientBatchSubscribe struct {
return h.BrokerServer.Publish(ctx, req, rsp) 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{} msg := &proto.SubscribeRequest{}
if err := stream.Recv(msg); err != nil { if err := stream.Recv(msg); err != nil {
return err 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 stream server.Stream
} }
func (s *brokerSubscribeStream) Close() error { func (s *brokerServiceSubscribeStream) Close() error {
return s.stream.Close() return s.stream.Close()
} }
func (s *brokerSubscribeStream) Context() context.Context { func (s *brokerServiceSubscribeStream) Context() context.Context {
return s.stream.Context() return s.stream.Context()
} }
func (s *brokerSubscribeStream) SendMsg(msg interface{}) error { func (s *brokerServiceSubscribeStream) SendMsg(msg interface{}) error {
return s.stream.Send(msg) return s.stream.Send(msg)
} }
func (s *brokerSubscribeStream) RecvMsg(msg interface{}) error { func (s *brokerServiceSubscribeStream) RecvMsg(msg interface{}) error {
return s.stream.Recv(msg) 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) return s.stream.Send(msg)
} }
func RegisterBrokerServer(s server.Server, sh BrokerServer, opts ...server.HandlerOption) error { func (h *brokerServiceServer) BatchSubscribe(ctx context.Context, stream server.Stream) error {
type broker interface { msg := &proto.BatchSubscribeRequest{}
Publish(ctx context.Context, req *proto.PublishRequest, rsp *proto.Empty) error 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 Subscribe(ctx context.Context, stream server.Stream) error
BatchSubscribe(ctx context.Context, stream server.Stream) error
} }
type Broker struct { type BrokerService struct {
broker brokerService
} }
h := &brokerServer{sh} h := &brokerServiceServer{sh}
var nopts []server.HandlerOption var nopts []server.HandlerOption
for _, endpoint := range BrokerEndpoints { for _, endpoint := range BrokerServiceEndpoints {
nopts = append(nopts, api.WithEndpoint(&endpoint)) 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...)...))
} }

View File

@ -20,44 +20,6 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) _ = 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 { type PublishRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -70,7 +32,7 @@ type PublishRequest struct {
func (x *PublishRequest) Reset() { func (x *PublishRequest) Reset() {
*x = PublishRequest{} *x = PublishRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_broker_proto_msgTypes[1] mi := &file_broker_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -83,7 +45,7 @@ func (x *PublishRequest) String() string {
func (*PublishRequest) ProtoMessage() {} func (*PublishRequest) ProtoMessage() {}
func (x *PublishRequest) ProtoReflect() protoreflect.Message { func (x *PublishRequest) ProtoReflect() protoreflect.Message {
mi := &file_broker_proto_msgTypes[1] mi := &file_broker_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -96,7 +58,7 @@ func (x *PublishRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead. // Deprecated: Use PublishRequest.ProtoReflect.Descriptor instead.
func (*PublishRequest) Descriptor() ([]byte, []int) { func (*PublishRequest) Descriptor() ([]byte, []int) {
return file_broker_proto_rawDescGZIP(), []int{1} return file_broker_proto_rawDescGZIP(), []int{0}
} }
func (x *PublishRequest) GetTopic() string { func (x *PublishRequest) GetTopic() string {
@ -113,6 +75,137 @@ func (x *PublishRequest) GetMessage() *Message {
return nil 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 { type SubscribeRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -125,7 +218,7 @@ type SubscribeRequest struct {
func (x *SubscribeRequest) Reset() { func (x *SubscribeRequest) Reset() {
*x = SubscribeRequest{} *x = SubscribeRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_broker_proto_msgTypes[2] mi := &file_broker_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -138,7 +231,7 @@ func (x *SubscribeRequest) String() string {
func (*SubscribeRequest) ProtoMessage() {} func (*SubscribeRequest) ProtoMessage() {}
func (x *SubscribeRequest) ProtoReflect() protoreflect.Message { func (x *SubscribeRequest) ProtoReflect() protoreflect.Message {
mi := &file_broker_proto_msgTypes[2] mi := &file_broker_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -151,7 +244,7 @@ func (x *SubscribeRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead. // Deprecated: Use SubscribeRequest.ProtoReflect.Descriptor instead.
func (*SubscribeRequest) Descriptor() ([]byte, []int) { func (*SubscribeRequest) Descriptor() ([]byte, []int) {
return file_broker_proto_rawDescGZIP(), []int{2} return file_broker_proto_rawDescGZIP(), []int{4}
} }
func (x *SubscribeRequest) GetTopic() string { func (x *SubscribeRequest) GetTopic() string {
@ -168,6 +261,61 @@ func (x *SubscribeRequest) GetGroup() string {
return "" 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 { type Message struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -180,7 +328,7 @@ type Message struct {
func (x *Message) Reset() { func (x *Message) Reset() {
*x = Message{} *x = Message{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_broker_proto_msgTypes[3] mi := &file_broker_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -193,7 +341,7 @@ func (x *Message) String() string {
func (*Message) ProtoMessage() {} func (*Message) ProtoMessage() {}
func (x *Message) ProtoReflect() protoreflect.Message { func (x *Message) ProtoReflect() protoreflect.Message {
mi := &file_broker_proto_msgTypes[3] mi := &file_broker_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -206,7 +354,7 @@ func (x *Message) ProtoReflect() protoreflect.Message {
// Deprecated: Use Message.ProtoReflect.Descriptor instead. // Deprecated: Use Message.ProtoReflect.Descriptor instead.
func (*Message) Descriptor() ([]byte, []int) { 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 { func (x *Message) GetHeader() map[string]string {
@ -227,39 +375,62 @@ var File_broker_proto protoreflect.FileDescriptor
var file_broker_proto_rawDesc = []byte{ var file_broker_proto_rawDesc = []byte{
0x0a, 0x0c, 0x62, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 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, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x22, 0x54, 0x0a, 0x0e, 0x50, 0x75, 0x62,
0x74, 0x79, 0x22, 0x54, 0x0a, 0x0e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74,
0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69,
0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, 0x63, 0x12, 0x2c, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01,
0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d,
0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22,
0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x3e, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x59, 0x0a, 0x13, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52,
0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18,
0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x2c, 0x0a, 0x07,
0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e,
0x09, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x73, 0x61, 0x67, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x01, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x50, 0x75,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x0a,
0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x14, 0x42, 0x61, 0x74, 0x63, 0x68, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x73,
0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3e, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x70,
0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12,
0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x43, 0x0a, 0x15, 0x42, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75,
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0x84, 0x01, 0x0a, 0x06, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14,
0x42, 0x72, 0x6f, 0x6b, 0x65, 0x72, 0x12, 0x38, 0x0a, 0x07, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x0a, 0x05, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74,
0x68, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x50, 0x75, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x02, 0x20,
0x62, 0x6c, 0x69, 0x73, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x73, 0x01, 0x28, 0x09, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x22, 0x90, 0x01, 0x0a, 0x07, 0x4d,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x36, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72,
0x12, 0x40, 0x0a, 0x09, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x12, 0x1b, 0x2e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65,
0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x73, 0x65, 0x72, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x12,
0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f,
0x30, 0x01, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x6f, 0x2e, 0x75, 0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x64, 0x79, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72,
0x6b, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2d, 0x62, 0x72, 0x6f, 0x6b, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x65, 0x72, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01,
0x6f, 0x74, 0x6f, 0x3b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x70, 0x62, 0x62, 0x06, 0x70, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xb4, 0x02,
0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@ -274,26 +445,34 @@ func file_broker_proto_rawDescGZIP() []byte {
return file_broker_proto_rawDescData 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{}{ var file_broker_proto_goTypes = []interface{}{
(*Empty)(nil), // 0: servicepb.Empty (*PublishRequest)(nil), // 0: servicepb.PublishRequest
(*PublishRequest)(nil), // 1: servicepb.PublishRequest (*BatchPublishRequest)(nil), // 1: servicepb.BatchPublishRequest
(*SubscribeRequest)(nil), // 2: servicepb.SubscribeRequest (*PublishResponse)(nil), // 2: servicepb.PublishResponse
(*Message)(nil), // 3: servicepb.Message (*BatchPublishResponse)(nil), // 3: servicepb.BatchPublishResponse
nil, // 4: servicepb.Message.HeaderEntry (*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{ var file_broker_proto_depIdxs = []int32{
3, // 0: servicepb.PublishRequest.message:type_name -> servicepb.Message 6, // 0: servicepb.PublishRequest.message:type_name -> servicepb.Message
4, // 1: servicepb.Message.header:type_name -> servicepb.Message.HeaderEntry 6, // 1: servicepb.BatchPublishRequest.message:type_name -> servicepb.Message
1, // 2: servicepb.Broker.Publish:input_type -> servicepb.PublishRequest 7, // 2: servicepb.Message.header:type_name -> servicepb.Message.HeaderEntry
2, // 3: servicepb.Broker.Subscribe:input_type -> servicepb.SubscribeRequest 0, // 3: servicepb.BrokerService.Publish:input_type -> servicepb.PublishRequest
0, // 4: servicepb.Broker.Publish:output_type -> servicepb.Empty 1, // 4: servicepb.BrokerService.BatchPublish:input_type -> servicepb.BatchPublishRequest
3, // 5: servicepb.Broker.Subscribe:output_type -> servicepb.Message 4, // 5: servicepb.BrokerService.Subscribe:input_type -> servicepb.SubscribeRequest
4, // [4:6] is the sub-list for method output_type 5, // 6: servicepb.BrokerService.BatchSubscribe:input_type -> servicepb.BatchSubscribeRequest
2, // [2:4] is the sub-list for method input_type 2, // 7: servicepb.BrokerService.Publish:output_type -> servicepb.PublishResponse
2, // [2:2] is the sub-list for extension type_name 3, // 8: servicepb.BrokerService.BatchPublish:output_type -> servicepb.BatchPublishResponse
2, // [2:2] is the sub-list for extension extendee 6, // 9: servicepb.BrokerService.Subscribe:output_type -> servicepb.Message
0, // [0:2] is the sub-list for field type_name 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() } func init() { file_broker_proto_init() }
@ -303,18 +482,6 @@ func file_broker_proto_init() {
} }
if !protoimpl.UnsafeEnabled { if !protoimpl.UnsafeEnabled {
file_broker_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 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 { switch v := v.(*PublishRequest); i {
case 0: case 0:
return &v.state return &v.state
@ -326,8 +493,20 @@ func file_broker_proto_init() {
return nil 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{} { file_broker_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SubscribeRequest); i { switch v := v.(*PublishResponse); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@ -339,6 +518,42 @@ func file_broker_proto_init() {
} }
} }
file_broker_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 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 { switch v := v.(*Message); i {
case 0: case 0:
return &v.state return &v.state
@ -357,7 +572,7 @@ func file_broker_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_broker_proto_rawDesc, RawDescriptor: file_broker_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 5, NumMessages: 8,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -3,24 +3,42 @@ syntax = "proto3";
package servicepb; package servicepb;
option go_package="go.unistack.org/micro-broker-service/v3/proto;servicepb"; option go_package="go.unistack.org/micro-broker-service/v3/proto;servicepb";
service Broker { service BrokerService {
rpc Publish(PublishRequest) returns (Empty) {}; rpc Publish(PublishRequest) returns (PublishResponse) {};
rpc BatchPublish(BatchPublishRequest) returns (BatchPublishResponse) {};
rpc Subscribe(SubscribeRequest) returns (stream Message) {}; rpc Subscribe(SubscribeRequest) returns (stream Message) {};
} rpc BatchSubscribe(BatchSubscribeRequest) returns (stream Message) {};
};
message Empty {}
message PublishRequest { message PublishRequest {
string topic = 1; string topic = 1;
Message message = 2; Message message = 2;
} };
message BatchPublishRequest {
string topic = 1;
repeated Message message = 2;
};
message PublishResponse {
};
message BatchPublishResponse {
};
message SubscribeRequest { message SubscribeRequest {
string topic = 1; string topic = 1;
string group = 2; string group = 2;
} };
message BatchSubscribeRequest {
string topic = 1;
string group = 2;
};
message Message { message Message {
map<string,string> header = 1; map<string,string> header = 1;
bytes body = 2; bytes body = 2;
} };

View File

@ -14,37 +14,48 @@ import (
// Requires gRPC-Go v1.32.0 or later. // Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7 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. // 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 { type BrokerServiceClient interface {
Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error)
Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, 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 cc grpc.ClientConnInterface
} }
func NewBrokerClient(cc grpc.ClientConnInterface) BrokerClient { func NewBrokerServiceClient(cc grpc.ClientConnInterface) BrokerServiceClient {
return &brokerClient{cc} return &brokerServiceClient{cc}
} }
func (c *brokerClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*Empty, error) { func (c *brokerServiceClient) Publish(ctx context.Context, in *PublishRequest, opts ...grpc.CallOption) (*PublishResponse, error) {
out := new(Empty) out := new(PublishResponse)
err := c.cc.Invoke(ctx, "/servicepb.Broker/Publish", in, out, opts...) err := c.cc.Invoke(ctx, "/servicepb.BrokerService/Publish", in, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return out, nil return out, nil
} }
func (c *brokerClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...grpc.CallOption) (Broker_SubscribeClient, error) { func (c *brokerServiceClient) BatchPublish(ctx context.Context, in *BatchPublishRequest, opts ...grpc.CallOption) (*BatchPublishResponse, error) {
stream, err := c.cc.NewStream(ctx, &Broker_ServiceDesc.Streams[0], "/servicepb.Broker/Subscribe", opts...) out := new(BatchPublishResponse)
err := c.cc.Invoke(ctx, "/servicepb.BrokerService/BatchPublish", in, out, opts...)
if err != nil { if err != nil {
return nil, err 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 { if err := x.ClientStream.SendMsg(in); err != nil {
return nil, err return nil, err
} }
@ -54,16 +65,16 @@ func (c *brokerClient) Subscribe(ctx context.Context, in *SubscribeRequest, opts
return x, nil return x, nil
} }
type Broker_SubscribeClient interface { type BrokerService_SubscribeClient interface {
Recv() (*Message, error) Recv() (*Message, error)
grpc.ClientStream grpc.ClientStream
} }
type brokerSubscribeClient struct { type brokerServiceSubscribeClient struct {
grpc.ClientStream grpc.ClientStream
} }
func (x *brokerSubscribeClient) Recv() (*Message, error) { func (x *brokerServiceSubscribeClient) Recv() (*Message, error) {
m := new(Message) m := new(Message)
if err := x.ClientStream.RecvMsg(m); err != nil { if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err return nil, err
@ -71,93 +82,181 @@ func (x *brokerSubscribeClient) Recv() (*Message, error) {
return m, nil return m, nil
} }
// BrokerServer is the server API for Broker service. func (c *brokerServiceClient) BatchSubscribe(ctx context.Context, in *BatchSubscribeRequest, opts ...grpc.CallOption) (BrokerService_BatchSubscribeClient, error) {
// All implementations must embed UnimplementedBrokerServer 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 // for forward compatibility
type BrokerServer interface { type BrokerServiceServer interface {
Publish(context.Context, *PublishRequest) (*Empty, error) Publish(context.Context, *PublishRequest) (*PublishResponse, error)
Subscribe(*SubscribeRequest, Broker_SubscribeServer) error BatchPublish(context.Context, *BatchPublishRequest) (*BatchPublishResponse, error)
mustEmbedUnimplementedBrokerServer() Subscribe(*SubscribeRequest, BrokerService_SubscribeServer) error
BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error
mustEmbedUnimplementedBrokerServiceServer()
} }
// UnimplementedBrokerServer must be embedded to have forward compatible implementations. // UnimplementedBrokerServiceServer must be embedded to have forward compatible implementations.
type UnimplementedBrokerServer struct { 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") 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") 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. // UnsafeBrokerServiceServer 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 // Use of this interface is not recommended, as added methods to BrokerServiceServer will
// result in compilation errors. // result in compilation errors.
type UnsafeBrokerServer interface { type UnsafeBrokerServiceServer interface {
mustEmbedUnimplementedBrokerServer() mustEmbedUnimplementedBrokerServiceServer()
} }
func RegisterBrokerServer(s grpc.ServiceRegistrar, srv BrokerServer) { func RegisterBrokerServiceServer(s grpc.ServiceRegistrar, srv BrokerServiceServer) {
s.RegisterService(&Broker_ServiceDesc, srv) 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) in := new(PublishRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
if interceptor == nil { if interceptor == nil {
return srv.(BrokerServer).Publish(ctx, in) return srv.(BrokerServiceServer).Publish(ctx, in)
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: "/servicepb.Broker/Publish", FullMethod: "/servicepb.BrokerService/Publish",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { 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) 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) m := new(SubscribeRequest)
if err := stream.RecvMsg(m); err != nil { if err := stream.RecvMsg(m); err != nil {
return err 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 Send(*Message) error
grpc.ServerStream grpc.ServerStream
} }
type brokerSubscribeServer struct { type brokerServiceSubscribeServer struct {
grpc.ServerStream grpc.ServerStream
} }
func (x *brokerSubscribeServer) Send(m *Message) error { func (x *brokerServiceSubscribeServer) Send(m *Message) error {
return x.ServerStream.SendMsg(m) 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, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
var Broker_ServiceDesc = grpc.ServiceDesc{ var BrokerService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "servicepb.Broker", ServiceName: "servicepb.BrokerService",
HandlerType: (*BrokerServer)(nil), HandlerType: (*BrokerServiceServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "Publish", MethodName: "Publish",
Handler: _Broker_Publish_Handler, Handler: _BrokerService_Publish_Handler,
},
{
MethodName: "BatchPublish",
Handler: _BrokerService_BatchPublish_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{ Streams: []grpc.StreamDesc{
{ {
StreamName: "Subscribe", StreamName: "Subscribe",
Handler: _Broker_Subscribe_Handler, Handler: _BrokerService_Subscribe_Handler,
ServerStreams: true,
},
{
StreamName: "BatchSubscribe",
Handler: _BrokerService_BatchSubscribe_Handler,
ServerStreams: true, ServerStreams: true,
}, },
}, },

View File

@ -11,12 +11,13 @@ import (
"go.unistack.org/micro/v3/broker" "go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v3/client" "go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/metadata"
) )
type serviceBroker struct { type serviceBroker struct {
addrs []string addrs []string
service string service string
client pbmicro.BrokerClient client pbmicro.BrokerServiceClient
init bool init bool
opts broker.Options opts broker.Options
} }
@ -73,7 +74,7 @@ func (b *serviceBroker) Init(opts ...broker.Option) error {
return fmt.Errorf("missing Client option") return fmt.Errorf("missing Client option")
} }
b.client = pbmicro.NewBrokerClient(b.service, cli) b.client = pbmicro.NewBrokerServiceClient(b.service, cli)
b.init = true b.init = true
return nil return nil
@ -83,7 +84,18 @@ func (b *serviceBroker) Options() broker.Options {
return b.opts 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 { func (b *serviceBroker) Publish(ctx context.Context, topic string, msg *broker.Message, opts ...broker.PublishOption) error {
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) { if logger.V(logger.TraceLevel) {
logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs) logger.Tracef(ctx, "Publishing to topic %s broker %v", topic, b.addrs)
} }
@ -94,8 +106,17 @@ func (b *serviceBroker) Publish(ctx context.Context, topic string, msg *broker.M
Body: msg.Body, Body: msg.Body,
}, },
}, client.WithAddress(b.addrs...)) }, client.WithAddress(b.addrs...))
if err != nil {
return err 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) { func (b *serviceBroker) Subscribe(ctx context.Context, topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
options := broker.NewSubscribeOptions(opts...) options := broker.NewSubscribeOptions(opts...)

View File

@ -12,7 +12,7 @@ type serviceSub struct {
topic string topic string
group string group string
handler broker.Handler handler broker.Handler
stream pbmicro.Broker_SubscribeClient stream pbmicro.BrokerService_SubscribeClient
closed chan bool closed chan bool
options broker.SubscribeOptions options broker.SubscribeOptions
} }
@ -39,6 +39,10 @@ func (s *serviceEvent) Error() error {
return s.err return s.err
} }
func (s *serviceEvent) SetError(err error) {
s.err = err
}
func (s *serviceSub) isClosed() bool { func (s *serviceSub) isClosed() bool {
select { select {
case <-s.closed: case <-s.closed: