mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 03:05:14 +00:00
187 lines
4.5 KiB
Go
187 lines
4.5 KiB
Go
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
|
// source: proto/mq.proto
|
|
|
|
package mq
|
|
|
|
import (
|
|
fmt "fmt"
|
|
proto "github.com/golang/protobuf/proto"
|
|
_ "google.golang.org/protobuf/types/known/structpb"
|
|
math "math"
|
|
)
|
|
|
|
import (
|
|
context "context"
|
|
api "github.com/micro/micro/v3/service/api"
|
|
client "github.com/micro/micro/v3/service/client"
|
|
server "github.com/micro/micro/v3/service/server"
|
|
)
|
|
|
|
// Reference imports to suppress errors if they are not otherwise used.
|
|
var _ = proto.Marshal
|
|
var _ = fmt.Errorf
|
|
var _ = math.Inf
|
|
|
|
// This is a compile-time assertion to ensure that this generated file
|
|
// is compatible with the proto package it is being compiled against.
|
|
// A compilation error at this line likely means your copy of the
|
|
// proto package needs to be updated.
|
|
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
|
|
|
// Reference imports to suppress errors if they are not otherwise used.
|
|
var _ api.Endpoint
|
|
var _ context.Context
|
|
var _ client.Option
|
|
var _ server.Option
|
|
|
|
// Api Endpoints for MQ service
|
|
|
|
func NewMQEndpoints() []*api.Endpoint {
|
|
return []*api.Endpoint{}
|
|
}
|
|
|
|
// Client API for MQ service
|
|
|
|
type MQService interface {
|
|
Publish(ctx context.Context, in *PublishRequest, opts ...client.CallOption) (*PublishResponse, error)
|
|
Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (MQ_SubscribeService, error)
|
|
}
|
|
|
|
type mQService struct {
|
|
c client.Client
|
|
name string
|
|
}
|
|
|
|
func NewMQService(name string, c client.Client) MQService {
|
|
return &mQService{
|
|
c: c,
|
|
name: name,
|
|
}
|
|
}
|
|
|
|
func (c *mQService) Publish(ctx context.Context, in *PublishRequest, opts ...client.CallOption) (*PublishResponse, error) {
|
|
req := c.c.NewRequest(c.name, "MQ.Publish", in)
|
|
out := new(PublishResponse)
|
|
err := c.c.Call(ctx, req, out, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (c *mQService) Subscribe(ctx context.Context, in *SubscribeRequest, opts ...client.CallOption) (MQ_SubscribeService, error) {
|
|
req := c.c.NewRequest(c.name, "MQ.Subscribe", &SubscribeRequest{})
|
|
stream, err := c.c.Stream(ctx, req, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := stream.Send(in); err != nil {
|
|
return nil, err
|
|
}
|
|
return &mQServiceSubscribe{stream}, nil
|
|
}
|
|
|
|
type MQ_SubscribeService interface {
|
|
Context() context.Context
|
|
SendMsg(interface{}) error
|
|
RecvMsg(interface{}) error
|
|
Close() error
|
|
Recv() (*SubscribeResponse, error)
|
|
}
|
|
|
|
type mQServiceSubscribe struct {
|
|
stream client.Stream
|
|
}
|
|
|
|
func (x *mQServiceSubscribe) Close() error {
|
|
return x.stream.Close()
|
|
}
|
|
|
|
func (x *mQServiceSubscribe) Context() context.Context {
|
|
return x.stream.Context()
|
|
}
|
|
|
|
func (x *mQServiceSubscribe) SendMsg(m interface{}) error {
|
|
return x.stream.Send(m)
|
|
}
|
|
|
|
func (x *mQServiceSubscribe) RecvMsg(m interface{}) error {
|
|
return x.stream.Recv(m)
|
|
}
|
|
|
|
func (x *mQServiceSubscribe) Recv() (*SubscribeResponse, error) {
|
|
m := new(SubscribeResponse)
|
|
err := x.stream.Recv(m)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// Server API for MQ service
|
|
|
|
type MQHandler interface {
|
|
Publish(context.Context, *PublishRequest, *PublishResponse) error
|
|
Subscribe(context.Context, *SubscribeRequest, MQ_SubscribeStream) error
|
|
}
|
|
|
|
func RegisterMQHandler(s server.Server, hdlr MQHandler, opts ...server.HandlerOption) error {
|
|
type mQ interface {
|
|
Publish(ctx context.Context, in *PublishRequest, out *PublishResponse) error
|
|
Subscribe(ctx context.Context, stream server.Stream) error
|
|
}
|
|
type MQ struct {
|
|
mQ
|
|
}
|
|
h := &mQHandler{hdlr}
|
|
return s.Handle(s.NewHandler(&MQ{h}, opts...))
|
|
}
|
|
|
|
type mQHandler struct {
|
|
MQHandler
|
|
}
|
|
|
|
func (h *mQHandler) Publish(ctx context.Context, in *PublishRequest, out *PublishResponse) error {
|
|
return h.MQHandler.Publish(ctx, in, out)
|
|
}
|
|
|
|
func (h *mQHandler) Subscribe(ctx context.Context, stream server.Stream) error {
|
|
m := new(SubscribeRequest)
|
|
if err := stream.Recv(m); err != nil {
|
|
return err
|
|
}
|
|
return h.MQHandler.Subscribe(ctx, m, &mQSubscribeStream{stream})
|
|
}
|
|
|
|
type MQ_SubscribeStream interface {
|
|
Context() context.Context
|
|
SendMsg(interface{}) error
|
|
RecvMsg(interface{}) error
|
|
Close() error
|
|
Send(*SubscribeResponse) error
|
|
}
|
|
|
|
type mQSubscribeStream struct {
|
|
stream server.Stream
|
|
}
|
|
|
|
func (x *mQSubscribeStream) Close() error {
|
|
return x.stream.Close()
|
|
}
|
|
|
|
func (x *mQSubscribeStream) Context() context.Context {
|
|
return x.stream.Context()
|
|
}
|
|
|
|
func (x *mQSubscribeStream) SendMsg(m interface{}) error {
|
|
return x.stream.Send(m)
|
|
}
|
|
|
|
func (x *mQSubscribeStream) RecvMsg(m interface{}) error {
|
|
return x.stream.Recv(m)
|
|
}
|
|
|
|
func (x *mQSubscribeStream) Send(m *SubscribeResponse) error {
|
|
return x.stream.Send(m)
|
|
}
|