Compare commits

..

4 Commits

Author SHA1 Message Date
78194a8863 update deps (#116)
Some checks failed
build / lint (push) Failing after 9s
build / test (push) Failing after 9s
codeql / analyze (go) (push) Failing after 14m57s
* update deps

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

Reviewed-on: #116
2024-09-20 18:41:11 +03:00
881eec8e36 Merge pull request 'regen' (#115) from updates into v3
Reviewed-on: #115
2023-03-25 22:17:59 +03:00
f2092f3649 Merge branch 'v3' into updates 2023-03-25 22:17:39 +03:00
6c623d0149 regen
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-03-25 22:16:14 +03:00
9 changed files with 69 additions and 1424 deletions

View File

@ -1,3 +1,3 @@
package service
//go:generate protoc -I./proto -I. --go-grpc_out=paths=source_relative:./proto --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,standalone=true,paths=source_relative:./micro proto/broker.proto
//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|grpc,standalone=true,paths=source_relative:./micro proto/broker.proto

19
go.mod
View File

@ -1,9 +1,20 @@
module go.unistack.org/micro-broker-service/v3
go 1.16
go 1.21
toolchain go1.23.1
require (
go.unistack.org/micro/v3 v3.10.11
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
go.unistack.org/micro-server-http/v3 v3.11.29
go.unistack.org/micro/v3 v3.10.91
google.golang.org/protobuf v1.34.2
)
require (
github.com/google/go-cmp v0.6.0 // indirect
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.0 // indirect
)

1159
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.5.3
// versions:
// - protoc-gen-go-micro v3.10.2
// - protoc v3.21.12
// source: broker.proto
package servicepb
@ -7,19 +9,16 @@ package servicepb
import (
context "context"
proto "go.unistack.org/micro-broker-service/v3/proto"
api "go.unistack.org/micro/v3/api"
v3 "go.unistack.org/micro-server-http/v3"
client "go.unistack.org/micro/v3/client"
)
var (
BrokerServiceName = "BrokerService"
BrokerServiceEndpoints = []api.Endpoint{}
)
func NewBrokerServiceEndpoints() []api.Endpoint {
return BrokerServiceEndpoints
}
var (
BrokerServiceServerEndpoints = []v3.EndpointMetadata{}
)
type BrokerServiceClient interface {
Publish(ctx context.Context, req *proto.PublishRequest, opts ...client.CallOption) (*proto.PublishResponse, error)

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.5.3
// protoc-gen-go-micro version: v3.10.2
// source: broker.proto
package servicepb
@ -7,7 +7,6 @@ package servicepb
import (
context "context"
proto "go.unistack.org/micro-broker-service/v3/proto"
api "go.unistack.org/micro/v3/api"
client "go.unistack.org/micro/v3/client"
server "go.unistack.org/micro/v3/server"
)
@ -58,6 +57,10 @@ func (s *brokerServiceClientSubscribe) Close() error {
return s.stream.Close()
}
func (s *brokerServiceClientSubscribe) CloseSend() error {
return s.stream.CloseSend()
}
func (s *brokerServiceClientSubscribe) Context() context.Context {
return s.stream.Context()
}
@ -97,6 +100,10 @@ func (s *brokerServiceClientBatchSubscribe) Close() error {
return s.stream.Close()
}
func (s *brokerServiceClientBatchSubscribe) CloseSend() error {
return s.stream.CloseSend()
}
func (s *brokerServiceClientBatchSubscribe) Context() context.Context {
return s.stream.Context()
}
@ -205,8 +212,5 @@ func RegisterBrokerServiceServer(s server.Server, sh BrokerServiceServer, opts .
}
h := &brokerServiceServer{sh}
var nopts []server.HandlerOption
for _, endpoint := range BrokerServiceEndpoints {
nopts = append(nopts, api.WithEndpoint(&endpoint))
}
return s.Handle(s.NewHandler(&BrokerService{h}, append(nopts, opts...)...))
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.3
// protoc v3.21.12
// source: broker.proto
package servicepb

View File

@ -1,264 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package servicepb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// 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 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 brokerServiceClient struct {
cc grpc.ClientConnInterface
}
func NewBrokerServiceClient(cc grpc.ClientConnInterface) BrokerServiceClient {
return &brokerServiceClient{cc}
}
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 *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
}
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
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type BrokerService_SubscribeClient interface {
Recv() (*Message, error)
grpc.ClientStream
}
type brokerServiceSubscribeClient struct {
grpc.ClientStream
}
func (x *brokerServiceSubscribeClient) Recv() (*Message, error) {
m := new(Message)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
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 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()
}
// UnimplementedBrokerServiceServer must be embedded to have forward compatible implementations.
type UnimplementedBrokerServiceServer struct {
}
func (UnimplementedBrokerServiceServer) Publish(context.Context, *PublishRequest) (*PublishResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Publish not implemented")
}
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 (UnimplementedBrokerServiceServer) BatchSubscribe(*BatchSubscribeRequest, BrokerService_BatchSubscribeServer) error {
return status.Errorf(codes.Unimplemented, "method BatchSubscribe not implemented")
}
func (UnimplementedBrokerServiceServer) mustEmbedUnimplementedBrokerServiceServer() {}
// 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 UnsafeBrokerServiceServer interface {
mustEmbedUnimplementedBrokerServiceServer()
}
func RegisterBrokerServiceServer(s grpc.ServiceRegistrar, srv BrokerServiceServer) {
s.RegisterService(&BrokerService_ServiceDesc, srv)
}
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.(BrokerServiceServer).Publish(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/servicepb.BrokerService/Publish",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(BrokerServiceServer).Publish(ctx, req.(*PublishRequest))
}
return interceptor(ctx, in, info, handler)
}
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.(BrokerServiceServer).Subscribe(m, &brokerServiceSubscribeServer{stream})
}
type BrokerService_SubscribeServer interface {
Send(*Message) error
grpc.ServerStream
}
type brokerServiceSubscribeServer struct {
grpc.ServerStream
}
func (x *brokerServiceSubscribeServer) Send(m *Message) error {
return x.ServerStream.SendMsg(m)
}
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 BrokerService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "servicepb.BrokerService",
HandlerType: (*BrokerServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Publish",
Handler: _BrokerService_Publish_Handler,
},
{
MethodName: "BatchPublish",
Handler: _BrokerService_BatchPublish_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "Subscribe",
Handler: _BrokerService_Subscribe_Handler,
ServerStreams: true,
},
{
StreamName: "BatchSubscribe",
Handler: _BrokerService_BatchSubscribe_Handler,
ServerStreams: true,
},
},
Metadata: "broker.proto",
}

View File

@ -14,12 +14,14 @@ import (
"go.unistack.org/micro/v3/metadata"
)
var _ broker.Broker = &serviceBroker{}
type serviceBroker struct {
addrs []string
service string
client pbmicro.BrokerServiceClient
init bool
service string
opts broker.Options
addrs []string
init bool
}
func (b *serviceBroker) Address() string {

View File

@ -6,6 +6,7 @@ import (
pbmicro "go.unistack.org/micro-broker-service/v3/micro"
"go.unistack.org/micro/v3/broker"
"go.unistack.org/micro/v3/logger"
"go.unistack.org/micro/v3/metadata"
)
type serviceSub struct {
@ -18,11 +19,16 @@ type serviceSub struct {
}
type serviceEvent struct {
ctx context.Context
topic string
err error
message *broker.Message
}
func (s *serviceEvent) Context() context.Context {
return s.ctx
}
func (s *serviceEvent) Topic() string {
return s.topic
}
@ -67,9 +73,10 @@ func (s *serviceSub) run(ctx context.Context) error {
for {
// TODO: do not fail silently
msg, err := s.stream.Recv()
ctx := metadata.NewIncomingContext(context.Background(), msg.Header)
if err != nil {
if logger.V(logger.TraceLevel) {
logger.Tracef(ctx, "Streaming error for subcription to topic %s: %v", s.Topic(), err)
logger.Tracef(ctx, "streaming error for subcription to topic %s: %v", s.Topic(), err)
}
// close the exit channel
@ -85,6 +92,7 @@ func (s *serviceSub) run(ctx context.Context) error {
}
p := &serviceEvent{
ctx: ctx,
topic: s.topic,
message: &broker.Message{
Header: msg.Header,