gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/broker/service/proto/broker.pb.micro.go (about) 1 // Code generated by protoc-gen-micro. DO NOT EDIT. 2 // source: micro/go-micro/broker/service/proto/broker.proto 3 4 package go_micro_broker 5 6 import ( 7 fmt "fmt" 8 proto "github.com/golang/protobuf/proto" 9 math "math" 10 ) 11 12 import ( 13 context "context" 14 client "gitee.com/liuxuezhan/go-micro-v1.18.0/client" 15 server "gitee.com/liuxuezhan/go-micro-v1.18.0/server" 16 ) 17 18 // Reference imports to suppress errors if they are not otherwise used. 19 var _ = proto.Marshal 20 var _ = fmt.Errorf 21 var _ = math.Inf 22 23 // This is a compile-time assertion to ensure that this generated file 24 // is compatible with the proto package it is being compiled against. 25 // A compilation error at this line likely means your copy of the 26 // proto package needs to be updated. 27 const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package 28 29 // Reference imports to suppress errors if they are not otherwise used. 30 var _ context.Context 31 var _ client.Option 32 var _ server.Option 33 34 // Client API for Broker service 35 36 type BrokerService interface { 37 Publish(ctx context.Context, in *PublishRequest, opts ...client.CallOption) (*Empty, error) 38 Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeService, error) 39 } 40 41 type brokerService struct { 42 c client.Client 43 name string 44 } 45 46 func NewBrokerService(name string, c client.Client) BrokerService { 47 if c == nil { 48 c = client.NewClient() 49 } 50 if len(name) == 0 { 51 name = "go.micro.broker" 52 } 53 return &brokerService{ 54 c: c, 55 name: name, 56 } 57 } 58 59 func (c *brokerService) Publish(ctx context.Context, in *PublishRequest, opts ...client.CallOption) (*Empty, error) { 60 req := c.c.NewRequest(c.name, "Broker.Publish", in) 61 out := new(Empty) 62 err := c.c.Call(ctx, req, out, opts...) 63 if err != nil { 64 return nil, err 65 } 66 return out, nil 67 } 68 69 func (c *brokerService) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (Broker_SubscribeService, error) { 70 req := c.c.NewRequest(c.name, "Broker.Subscribe", &SubscribeRequest{}) 71 stream, err := c.c.Stream(ctx, req, opts...) 72 if err != nil { 73 return nil, err 74 } 75 if err := stream.Send(in); err != nil { 76 return nil, err 77 } 78 return &brokerServiceSubscribe{stream}, nil 79 } 80 81 type Broker_SubscribeService interface { 82 SendMsg(interface{}) error 83 RecvMsg(interface{}) error 84 Close() error 85 Recv() (*Message, error) 86 } 87 88 type brokerServiceSubscribe struct { 89 stream client.Stream 90 } 91 92 func (x *brokerServiceSubscribe) Close() error { 93 return x.stream.Close() 94 } 95 96 func (x *brokerServiceSubscribe) SendMsg(m interface{}) error { 97 return x.stream.Send(m) 98 } 99 100 func (x *brokerServiceSubscribe) RecvMsg(m interface{}) error { 101 return x.stream.Recv(m) 102 } 103 104 func (x *brokerServiceSubscribe) Recv() (*Message, error) { 105 m := new(Message) 106 err := x.stream.Recv(m) 107 if err != nil { 108 return nil, err 109 } 110 return m, nil 111 } 112 113 // Server API for Broker service 114 115 type BrokerHandler interface { 116 Publish(context.Context, *PublishRequest, *Empty) error 117 Subscribe(context.Context, *SubscribeRequest, Broker_SubscribeStream) error 118 } 119 120 func RegisterBrokerHandler(s server.Server, hdlr BrokerHandler, opts ...server.HandlerOption) error { 121 type broker interface { 122 Publish(ctx context.Context, in *PublishRequest, out *Empty) error 123 Subscribe(ctx context.Context, stream server.Stream) error 124 } 125 type Broker struct { 126 broker 127 } 128 h := &brokerHandler{hdlr} 129 return s.Handle(s.NewHandler(&Broker{h}, opts...)) 130 } 131 132 type brokerHandler struct { 133 BrokerHandler 134 } 135 136 func (h *brokerHandler) Publish(ctx context.Context, in *PublishRequest, out *Empty) error { 137 return h.BrokerHandler.Publish(ctx, in, out) 138 } 139 140 func (h *brokerHandler) Subscribe(ctx context.Context, stream server.Stream) error { 141 m := new(SubscribeRequest) 142 if err := stream.Recv(m); err != nil { 143 return err 144 } 145 return h.BrokerHandler.Subscribe(ctx, m, &brokerSubscribeStream{stream}) 146 } 147 148 type Broker_SubscribeStream interface { 149 SendMsg(interface{}) error 150 RecvMsg(interface{}) error 151 Close() error 152 Send(*Message) error 153 } 154 155 type brokerSubscribeStream struct { 156 stream server.Stream 157 } 158 159 func (x *brokerSubscribeStream) Close() error { 160 return x.stream.Close() 161 } 162 163 func (x *brokerSubscribeStream) SendMsg(m interface{}) error { 164 return x.stream.Send(m) 165 } 166 167 func (x *brokerSubscribeStream) RecvMsg(m interface{}) error { 168 return x.stream.Recv(m) 169 } 170 171 func (x *brokerSubscribeStream) Send(m *Message) error { 172 return x.stream.Send(m) 173 }