mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:50:18 +00:00
MF-1455 - Update Versions of Protobuf (#1704)
* initial commit * add protoc-gen-gofast * update generated files * fix linting * fix consumers error on message conversion * fix copying values on transformers * initial commit * initial commit * add protoc-gen-gofast * update generated files * fix linting * fix consumers error on message conversion * fix copying values on transformers * embedded for forward compatible. * remove gogo * embedded for forward compatible. * update protoc compiler * fix linting * remove hex comment Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
This commit is contained in:
@@ -77,8 +77,8 @@ test:
|
||||
go test -mod=vendor -v -race -count 1 -tags test $(shell go list ./... | grep -v 'vendor\|cmd')
|
||||
|
||||
proto:
|
||||
protoc --gofast_out=plugins=grpc:. *.proto
|
||||
protoc --gofast_out=plugins=grpc:. pkg/messaging/*.proto
|
||||
protoc -I. --go_out=. --go_opt=paths=source_relative pkg/messaging/*.proto
|
||||
protoc -I. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative *.proto
|
||||
|
||||
$(SERVICES):
|
||||
$(call compile_service,$(@))
|
||||
|
||||
+1216
-4948
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,8 @@ package mainflux;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
option go_package = "./mainflux";
|
||||
|
||||
service ThingsService {
|
||||
rpc CanAccessByKey(AccessByKeyReq) returns (ThingID) {}
|
||||
rpc IsChannelOwner(ChannelOwnerReq) returns (google.protobuf.Empty) {}
|
||||
|
||||
@@ -143,42 +143,42 @@ func TestIdentify(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
token string
|
||||
idt mainflux.UserIdentity
|
||||
idt *mainflux.UserIdentity
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
{
|
||||
desc: "identify user with user token",
|
||||
token: loginSecret,
|
||||
idt: mainflux.UserIdentity{Email: email, Id: id},
|
||||
idt: &mainflux.UserIdentity{Email: email, Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with recovery token",
|
||||
token: recoverySecret,
|
||||
idt: mainflux.UserIdentity{Email: email, Id: id},
|
||||
idt: &mainflux.UserIdentity{Email: email, Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with API token",
|
||||
token: apiSecret,
|
||||
idt: mainflux.UserIdentity{Email: email, Id: id},
|
||||
idt: &mainflux.UserIdentity{Email: email, Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with invalid user token",
|
||||
token: "invalid",
|
||||
idt: mainflux.UserIdentity{},
|
||||
idt: &mainflux.UserIdentity{},
|
||||
err: status.Error(codes.Unauthenticated, "unauthenticated access"),
|
||||
code: codes.Unauthenticated,
|
||||
},
|
||||
{
|
||||
desc: "identify user with empty token",
|
||||
token: "",
|
||||
idt: mainflux.UserIdentity{},
|
||||
idt: &mainflux.UserIdentity{},
|
||||
err: status.Error(codes.InvalidArgument, "received invalid token request"),
|
||||
code: codes.Unauthenticated,
|
||||
},
|
||||
@@ -187,7 +187,7 @@ func TestIdentify(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
idt, err := client.Identify(context.Background(), &mainflux.Token{Value: tc.token})
|
||||
if idt != nil {
|
||||
assert.Equal(t, tc.idt, *idt, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.idt, *idt))
|
||||
assert.Equal(t, tc.idt, idt, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.idt, idt))
|
||||
}
|
||||
e, ok := status.FromError(err)
|
||||
assert.True(t, ok, "gRPC status can't be extracted from the error")
|
||||
@@ -209,7 +209,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject string
|
||||
object string
|
||||
relation string
|
||||
ar mainflux.AuthorizeRes
|
||||
ar *mainflux.AuthorizeRes
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
@@ -219,7 +219,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: authoritiesObj,
|
||||
relation: memberRelation,
|
||||
ar: mainflux.AuthorizeRes{Authorized: true},
|
||||
ar: &mainflux.AuthorizeRes{Authorized: true},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
@@ -229,7 +229,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: authoritiesObj,
|
||||
relation: "unauthorizedRelation",
|
||||
ar: mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -239,7 +239,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: "unauthorizedobject",
|
||||
relation: memberRelation,
|
||||
ar: mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -249,7 +249,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: "unauthorizedSubject",
|
||||
object: authoritiesObj,
|
||||
relation: memberRelation,
|
||||
ar: mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -259,7 +259,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
ar: mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.InvalidArgument,
|
||||
},
|
||||
@@ -267,7 +267,7 @@ func TestAuthorize(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
ar, err := client.Authorize(context.Background(), &mainflux.AuthorizeReq{Sub: tc.subject, Obj: tc.object, Act: tc.relation})
|
||||
if ar != nil {
|
||||
assert.Equal(t, tc.ar, *ar, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, *ar))
|
||||
assert.Equal(t, tc.ar, ar, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, ar))
|
||||
}
|
||||
|
||||
e, ok := status.FromError(err)
|
||||
@@ -292,7 +292,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject string
|
||||
object string
|
||||
relation string
|
||||
ar mainflux.AddPolicyRes
|
||||
ar *mainflux.AddPolicyRes
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
@@ -302,7 +302,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject: id,
|
||||
object: groupAdminObj,
|
||||
relation: memberRelation,
|
||||
ar: mainflux.AddPolicyRes{Authorized: true},
|
||||
ar: &mainflux.AddPolicyRes{Authorized: true},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
@@ -312,7 +312,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
ar: mainflux.AddPolicyRes{Authorized: false},
|
||||
ar: &mainflux.AddPolicyRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.InvalidArgument,
|
||||
},
|
||||
@@ -320,7 +320,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
apr, err := client.AddPolicy(context.Background(), &mainflux.AddPolicyReq{Sub: tc.subject, Obj: tc.object, Act: tc.relation})
|
||||
if apr != nil {
|
||||
assert.Equal(t, tc.ar, *apr, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, *apr))
|
||||
assert.Equal(t, tc.ar, apr, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, apr))
|
||||
}
|
||||
|
||||
e, ok := status.FromError(err)
|
||||
|
||||
@@ -29,6 +29,7 @@ type grpcServer struct {
|
||||
listPolicies kitgrpc.Handler
|
||||
assign kitgrpc.Handler
|
||||
members kitgrpc.Handler
|
||||
mainflux.UnimplementedAuthServiceServer
|
||||
}
|
||||
|
||||
// NewServer returns new AuthServiceServer instance.
|
||||
|
||||
+552
@@ -0,0 +1,552 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.21.12
|
||||
// source: auth.proto
|
||||
|
||||
package mainflux
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
// 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
|
||||
|
||||
// ThingsServiceClient is the client API for ThingsService 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 ThingsServiceClient interface {
|
||||
CanAccessByKey(ctx context.Context, in *AccessByKeyReq, opts ...grpc.CallOption) (*ThingID, error)
|
||||
IsChannelOwner(ctx context.Context, in *ChannelOwnerReq, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
CanAccessByID(ctx context.Context, in *AccessByIDReq, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
Identify(ctx context.Context, in *Token, opts ...grpc.CallOption) (*ThingID, error)
|
||||
}
|
||||
|
||||
type thingsServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewThingsServiceClient(cc grpc.ClientConnInterface) ThingsServiceClient {
|
||||
return &thingsServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *thingsServiceClient) CanAccessByKey(ctx context.Context, in *AccessByKeyReq, opts ...grpc.CallOption) (*ThingID, error) {
|
||||
out := new(ThingID)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/CanAccessByKey", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *thingsServiceClient) IsChannelOwner(ctx context.Context, in *ChannelOwnerReq, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/IsChannelOwner", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *thingsServiceClient) CanAccessByID(ctx context.Context, in *AccessByIDReq, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/CanAccessByID", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *thingsServiceClient) Identify(ctx context.Context, in *Token, opts ...grpc.CallOption) (*ThingID, error) {
|
||||
out := new(ThingID)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/Identify", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ThingsServiceServer is the server API for ThingsService service.
|
||||
// All implementations must embed UnimplementedThingsServiceServer
|
||||
// for forward compatibility
|
||||
type ThingsServiceServer interface {
|
||||
CanAccessByKey(context.Context, *AccessByKeyReq) (*ThingID, error)
|
||||
IsChannelOwner(context.Context, *ChannelOwnerReq) (*emptypb.Empty, error)
|
||||
CanAccessByID(context.Context, *AccessByIDReq) (*emptypb.Empty, error)
|
||||
Identify(context.Context, *Token) (*ThingID, error)
|
||||
mustEmbedUnimplementedThingsServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedThingsServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedThingsServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedThingsServiceServer) CanAccessByKey(context.Context, *AccessByKeyReq) (*ThingID, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CanAccessByKey not implemented")
|
||||
}
|
||||
func (UnimplementedThingsServiceServer) IsChannelOwner(context.Context, *ChannelOwnerReq) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method IsChannelOwner not implemented")
|
||||
}
|
||||
func (UnimplementedThingsServiceServer) CanAccessByID(context.Context, *AccessByIDReq) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CanAccessByID not implemented")
|
||||
}
|
||||
func (UnimplementedThingsServiceServer) Identify(context.Context, *Token) (*ThingID, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Identify not implemented")
|
||||
}
|
||||
func (UnimplementedThingsServiceServer) mustEmbedUnimplementedThingsServiceServer() {}
|
||||
|
||||
// UnsafeThingsServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to ThingsServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeThingsServiceServer interface {
|
||||
mustEmbedUnimplementedThingsServiceServer()
|
||||
}
|
||||
|
||||
func RegisterThingsServiceServer(s grpc.ServiceRegistrar, srv ThingsServiceServer) {
|
||||
s.RegisterService(&ThingsService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _ThingsService_CanAccessByKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AccessByKeyReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ThingsServiceServer).CanAccessByKey(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.ThingsService/CanAccessByKey",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ThingsServiceServer).CanAccessByKey(ctx, req.(*AccessByKeyReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ThingsService_IsChannelOwner_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ChannelOwnerReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ThingsServiceServer).IsChannelOwner(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.ThingsService/IsChannelOwner",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ThingsServiceServer).IsChannelOwner(ctx, req.(*ChannelOwnerReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ThingsService_CanAccessByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AccessByIDReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ThingsServiceServer).CanAccessByID(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.ThingsService/CanAccessByID",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ThingsServiceServer).CanAccessByID(ctx, req.(*AccessByIDReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ThingsService_Identify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Token)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ThingsServiceServer).Identify(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.ThingsService/Identify",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ThingsServiceServer).Identify(ctx, req.(*Token))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// ThingsService_ServiceDesc is the grpc.ServiceDesc for ThingsService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var ThingsService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "mainflux.ThingsService",
|
||||
HandlerType: (*ThingsServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CanAccessByKey",
|
||||
Handler: _ThingsService_CanAccessByKey_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "IsChannelOwner",
|
||||
Handler: _ThingsService_IsChannelOwner_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CanAccessByID",
|
||||
Handler: _ThingsService_CanAccessByID_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Identify",
|
||||
Handler: _ThingsService_Identify_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "auth.proto",
|
||||
}
|
||||
|
||||
// AuthServiceClient is the client API for AuthService 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 AuthServiceClient interface {
|
||||
Issue(ctx context.Context, in *IssueReq, opts ...grpc.CallOption) (*Token, error)
|
||||
Identify(ctx context.Context, in *Token, opts ...grpc.CallOption) (*UserIdentity, error)
|
||||
Authorize(ctx context.Context, in *AuthorizeReq, opts ...grpc.CallOption) (*AuthorizeRes, error)
|
||||
AddPolicy(ctx context.Context, in *AddPolicyReq, opts ...grpc.CallOption) (*AddPolicyRes, error)
|
||||
DeletePolicy(ctx context.Context, in *DeletePolicyReq, opts ...grpc.CallOption) (*DeletePolicyRes, error)
|
||||
ListPolicies(ctx context.Context, in *ListPoliciesReq, opts ...grpc.CallOption) (*ListPoliciesRes, error)
|
||||
Assign(ctx context.Context, in *Assignment, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
Members(ctx context.Context, in *MembersReq, opts ...grpc.CallOption) (*MembersRes, error)
|
||||
}
|
||||
|
||||
type authServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient {
|
||||
return &authServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Issue(ctx context.Context, in *IssueReq, opts ...grpc.CallOption) (*Token, error) {
|
||||
out := new(Token)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/Issue", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Identify(ctx context.Context, in *Token, opts ...grpc.CallOption) (*UserIdentity, error) {
|
||||
out := new(UserIdentity)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/Identify", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Authorize(ctx context.Context, in *AuthorizeReq, opts ...grpc.CallOption) (*AuthorizeRes, error) {
|
||||
out := new(AuthorizeRes)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/Authorize", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) AddPolicy(ctx context.Context, in *AddPolicyReq, opts ...grpc.CallOption) (*AddPolicyRes, error) {
|
||||
out := new(AddPolicyRes)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/AddPolicy", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) DeletePolicy(ctx context.Context, in *DeletePolicyReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
out := new(DeletePolicyRes)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/DeletePolicy", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListPolicies(ctx context.Context, in *ListPoliciesReq, opts ...grpc.CallOption) (*ListPoliciesRes, error) {
|
||||
out := new(ListPoliciesRes)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/ListPolicies", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Assign(ctx context.Context, in *Assignment, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/Assign", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Members(ctx context.Context, in *MembersReq, opts ...grpc.CallOption) (*MembersRes, error) {
|
||||
out := new(MembersRes)
|
||||
err := c.cc.Invoke(ctx, "/mainflux.AuthService/Members", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AuthServiceServer is the server API for AuthService service.
|
||||
// All implementations must embed UnimplementedAuthServiceServer
|
||||
// for forward compatibility
|
||||
type AuthServiceServer interface {
|
||||
Issue(context.Context, *IssueReq) (*Token, error)
|
||||
Identify(context.Context, *Token) (*UserIdentity, error)
|
||||
Authorize(context.Context, *AuthorizeReq) (*AuthorizeRes, error)
|
||||
AddPolicy(context.Context, *AddPolicyReq) (*AddPolicyRes, error)
|
||||
DeletePolicy(context.Context, *DeletePolicyReq) (*DeletePolicyRes, error)
|
||||
ListPolicies(context.Context, *ListPoliciesReq) (*ListPoliciesRes, error)
|
||||
Assign(context.Context, *Assignment) (*emptypb.Empty, error)
|
||||
Members(context.Context, *MembersReq) (*MembersRes, error)
|
||||
mustEmbedUnimplementedAuthServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedAuthServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedAuthServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedAuthServiceServer) Issue(context.Context, *IssueReq) (*Token, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Issue not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Identify(context.Context, *Token) (*UserIdentity, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Identify not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Authorize(context.Context, *AuthorizeReq) (*AuthorizeRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Authorize not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) AddPolicy(context.Context, *AddPolicyReq) (*AddPolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddPolicy not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) DeletePolicy(context.Context, *DeletePolicyReq) (*DeletePolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeletePolicy not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListPolicies(context.Context, *ListPoliciesReq) (*ListPoliciesRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListPolicies not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Assign(context.Context, *Assignment) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Assign not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Members(context.Context, *MembersReq) (*MembersRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Members not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {}
|
||||
|
||||
// UnsafeAuthServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to AuthServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeAuthServiceServer interface {
|
||||
mustEmbedUnimplementedAuthServiceServer()
|
||||
}
|
||||
|
||||
func RegisterAuthServiceServer(s grpc.ServiceRegistrar, srv AuthServiceServer) {
|
||||
s.RegisterService(&AuthService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _AuthService_Issue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IssueReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Issue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/Issue",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Issue(ctx, req.(*IssueReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Identify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Token)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Identify(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/Identify",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Identify(ctx, req.(*Token))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Authorize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AuthorizeReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Authorize(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/Authorize",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Authorize(ctx, req.(*AuthorizeReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_AddPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddPolicyReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).AddPolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/AddPolicy",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).AddPolicy(ctx, req.(*AddPolicyReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_DeletePolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeletePolicyReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).DeletePolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/DeletePolicy",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).DeletePolicy(ctx, req.(*DeletePolicyReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListPoliciesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListPolicies(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/ListPolicies",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListPolicies(ctx, req.(*ListPoliciesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Assign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Assignment)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Assign(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/Assign",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Assign(ctx, req.(*Assignment))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Members_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(MembersReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Members(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/mainflux.AuthService/Members",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Members(ctx, req.(*MembersReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var AuthService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "mainflux.AuthService",
|
||||
HandlerType: (*AuthServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Issue",
|
||||
Handler: _AuthService_Issue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Identify",
|
||||
Handler: _AuthService_Identify_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Authorize",
|
||||
Handler: _AuthService_Authorize_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddPolicy",
|
||||
Handler: _AuthService_AddPolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeletePolicy",
|
||||
Handler: _AuthService_DeletePolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListPolicies",
|
||||
Handler: _AuthService_ListPolicies_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Assign",
|
||||
Handler: _AuthService_Assign_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Members",
|
||||
Handler: _AuthService_Members_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "auth.proto",
|
||||
}
|
||||
+4
-4
@@ -307,12 +307,12 @@ func newService(id string, ps messaging.PubSub, chanID string, users mainflux.Au
|
||||
}
|
||||
|
||||
func handle(logger logger.Logger, chanID string, svc twins.Service) handlerFunc {
|
||||
return func(msg messaging.Message) error {
|
||||
return func(msg *messaging.Message) error {
|
||||
if msg.Channel == chanID {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := svc.SaveStates(&msg); err != nil {
|
||||
if err := svc.SaveStates(msg); err != nil {
|
||||
logger.Error(fmt.Sprintf("State save failed: %s", err))
|
||||
return err
|
||||
}
|
||||
@@ -355,9 +355,9 @@ func startHTTPServer(ctx context.Context, handler http.Handler, port string, cfg
|
||||
}
|
||||
}
|
||||
|
||||
type handlerFunc func(msg messaging.Message) error
|
||||
type handlerFunc func(msg *messaging.Message) error
|
||||
|
||||
func (h handlerFunc) Handle(msg messaging.Message) error {
|
||||
func (h handlerFunc) Handle(msg *messaging.Message) error {
|
||||
return h(msg)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ var ErrUnsubscribe = errors.New("unable to unsubscribe")
|
||||
// Service specifies CoAP service API.
|
||||
type Service interface {
|
||||
// Publish Messssage
|
||||
Publish(ctx context.Context, key string, msg messaging.Message) error
|
||||
Publish(ctx context.Context, key string, msg *messaging.Message) error
|
||||
|
||||
// Subscribes to channel with specified id, subtopic and adds subscription to
|
||||
// service map of subscriptions under given ID.
|
||||
@@ -55,7 +55,7 @@ func New(auth mainflux.ThingsServiceClient, pubsub messaging.PubSub) Service {
|
||||
return as
|
||||
}
|
||||
|
||||
func (svc *adapterService) Publish(ctx context.Context, key string, msg messaging.Message) error {
|
||||
func (svc *adapterService) Publish(ctx context.Context, key string, msg *messaging.Message) error {
|
||||
ar := &mainflux.AccessByKeyReq{
|
||||
Token: key,
|
||||
ChanID: msg.Channel,
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ func LoggingMiddleware(svc coap.Service, logger log.Logger) coap.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, key string, msg messaging.Message) (err error) {
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, key string, msg *messaging.Message) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
destChannel := msg.Channel
|
||||
if msg.Subtopic != "" {
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func MetricsMiddleware(svc coap.Service, counter metrics.Counter, latency metric
|
||||
}
|
||||
}
|
||||
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, key string, msg messaging.Message) error {
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, key string, msg *messaging.Message) error {
|
||||
defer func(begin time.Time) {
|
||||
mm.counter.With("method", "publish").Add(1)
|
||||
mm.latency.With("method", "publish").Observe(time.Since(begin).Seconds())
|
||||
|
||||
@@ -118,7 +118,7 @@ func handler(w mux.ResponseWriter, m *mux.Message) {
|
||||
}
|
||||
}
|
||||
|
||||
func handleGet(m *mux.Message, c mux.Client, msg messaging.Message, key string) error {
|
||||
func handleGet(m *mux.Message, c mux.Client, msg *messaging.Message, key string) error {
|
||||
var obs uint32
|
||||
obs, err := m.Options.Observe()
|
||||
if err != nil {
|
||||
@@ -132,24 +132,24 @@ func handleGet(m *mux.Message, c mux.Client, msg messaging.Message, key string)
|
||||
return service.Unsubscribe(context.Background(), key, msg.Channel, msg.Subtopic, m.Token.String())
|
||||
}
|
||||
|
||||
func decodeMessage(msg *mux.Message) (messaging.Message, error) {
|
||||
func decodeMessage(msg *mux.Message) (*messaging.Message, error) {
|
||||
if msg.Options == nil {
|
||||
return messaging.Message{}, errBadOptions
|
||||
return &messaging.Message{}, errBadOptions
|
||||
}
|
||||
path, err := msg.Options.Path()
|
||||
if err != nil {
|
||||
return messaging.Message{}, err
|
||||
return &messaging.Message{}, err
|
||||
}
|
||||
channelParts := channelPartRegExp.FindStringSubmatch(path)
|
||||
if len(channelParts) < numGroups {
|
||||
return messaging.Message{}, errMalformedSubtopic
|
||||
return &messaging.Message{}, errMalformedSubtopic
|
||||
}
|
||||
|
||||
st, err := parseSubtopic(channelParts[channelGroup])
|
||||
if err != nil {
|
||||
return messaging.Message{}, err
|
||||
return &messaging.Message{}, err
|
||||
}
|
||||
ret := messaging.Message{
|
||||
ret := &messaging.Message{
|
||||
Protocol: protocol,
|
||||
Channel: channelParts[1],
|
||||
Subtopic: st,
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import (
|
||||
type Client interface {
|
||||
// In CoAP terminology, Token similar to the Session ID.
|
||||
Token() string
|
||||
Handle(m messaging.Message) error
|
||||
Handle(m *messaging.Message) error
|
||||
Cancel() error
|
||||
Done() <-chan struct{}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (c *client) Token() string {
|
||||
return c.token.String()
|
||||
}
|
||||
|
||||
func (c *client) Handle(msg messaging.Message) error {
|
||||
func (c *client) Handle(msg *messaging.Message) error {
|
||||
m := message.Message{
|
||||
Code: codes.Content,
|
||||
Token: c.token,
|
||||
|
||||
@@ -50,7 +50,7 @@ func Start(id string, sub messaging.Subscriber, consumer Consumer, configPath st
|
||||
}
|
||||
|
||||
func handle(t transformers.Transformer, c Consumer) handleFunc {
|
||||
return func(msg messaging.Message) error {
|
||||
return func(msg *messaging.Message) error {
|
||||
m := interface{}(msg)
|
||||
var err error
|
||||
if t != nil {
|
||||
@@ -63,9 +63,9 @@ func handle(t transformers.Transformer, c Consumer) handleFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type handleFunc func(msg messaging.Message) error
|
||||
type handleFunc func(msg *messaging.Message) error
|
||||
|
||||
func (h handleFunc) Handle(msg messaging.Message) error {
|
||||
func (h handleFunc) Handle(msg *messaging.Message) error {
|
||||
return h(msg)
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func NewNotifier() notifiers.Notifier {
|
||||
return notifier{}
|
||||
}
|
||||
|
||||
func (n notifier) Notify(from string, to []string, msg messaging.Message) error {
|
||||
func (n notifier) Notify(from string, to []string, msg *messaging.Message) error {
|
||||
for _, t := range to {
|
||||
if t == invalidSender {
|
||||
return notifiers.ErrNotify
|
||||
|
||||
@@ -16,5 +16,5 @@ var ErrNotify = errors.New("Error sending notification")
|
||||
type Notifier interface {
|
||||
// Notify method is used to send notification for the
|
||||
// received message to the provided list of receivers.
|
||||
Notify(from string, to []string, msg messaging.Message) error
|
||||
Notify(from string, to []string, msg *messaging.Message) error
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func (ns *notifierService) RemoveSubscription(ctx context.Context, token, id str
|
||||
}
|
||||
|
||||
func (ns *notifierService) Consume(message interface{}) error {
|
||||
msg, ok := message.(messaging.Message)
|
||||
msg, ok := message.(*messaging.Message)
|
||||
if !ok {
|
||||
return ErrMessage
|
||||
}
|
||||
|
||||
@@ -306,16 +306,16 @@ func TestConsume(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "test success",
|
||||
msg: msg,
|
||||
msg: &msg,
|
||||
},
|
||||
{
|
||||
desc: "test fail",
|
||||
msg: errMsg,
|
||||
msg: &errMsg,
|
||||
err: notifiers.ErrNotify,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func New(cfg Config) notifiers.Notifier {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (n *notifier) Notify(from string, to []string, msg messaging.Message) error {
|
||||
func (n *notifier) Notify(from string, to []string, msg *messaging.Message) error {
|
||||
send := &smpp.ShortMessage{
|
||||
Src: from,
|
||||
DstList: to,
|
||||
|
||||
@@ -27,7 +27,7 @@ func New(agent *email.Agent) notifiers.Notifier {
|
||||
return ¬ifier{agent: agent}
|
||||
}
|
||||
|
||||
func (n *notifier) Notify(from string, to []string, msg messaging.Message) error {
|
||||
func (n *notifier) Notify(from string, to []string, msg *messaging.Message) error {
|
||||
subject := fmt.Sprintf(`Notification for Channel %s`, msg.Channel)
|
||||
if msg.Subtopic != "" {
|
||||
subject = fmt.Sprintf("%s and subtopic %s", subject, msg.Subtopic)
|
||||
|
||||
@@ -13,7 +13,6 @@ require (
|
||||
github.com/go-zoo/bone v1.3.0
|
||||
github.com/gocql/gocql v1.2.1
|
||||
github.com/gofrs/uuid v4.3.0+incompatible
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang-jwt/jwt/v4 v4.4.2
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/gopcua/opcua v0.1.6
|
||||
@@ -49,6 +48,7 @@ require (
|
||||
golang.org/x/sync v0.1.0
|
||||
gonum.org/v1/gonum v0.12.0
|
||||
google.golang.org/grpc v1.50.1
|
||||
google.golang.org/protobuf v1.28.1
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
)
|
||||
|
||||
@@ -73,6 +73,7 @@ require (
|
||||
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
|
||||
github.com/go-kit/log v0.2.1 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
|
||||
@@ -150,7 +151,6 @@ require (
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
golang.org/x/tools v0.2.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import (
|
||||
// Service specifies coap service API.
|
||||
type Service interface {
|
||||
// Publish Messssage
|
||||
Publish(ctx context.Context, token string, msg messaging.Message) error
|
||||
Publish(ctx context.Context, token string, msg *messaging.Message) error
|
||||
}
|
||||
|
||||
var _ Service = (*adapterService)(nil)
|
||||
@@ -33,7 +33,7 @@ func New(publisher messaging.Publisher, things mainflux.ThingsServiceClient) Ser
|
||||
}
|
||||
}
|
||||
|
||||
func (as *adapterService) Publish(ctx context.Context, token string, msg messaging.Message) error {
|
||||
func (as *adapterService) Publish(ctx context.Context, token string, msg *messaging.Message) error {
|
||||
ar := &mainflux.AccessByKeyReq{
|
||||
Token: token,
|
||||
ChanID: msg.Channel,
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ func LoggingMiddleware(svc http.Service, logger log.Logger) http.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, token string, msg messaging.Message) (err error) {
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, token string, msg *messaging.Message) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
destChannel := msg.Channel
|
||||
if msg.Subtopic != "" {
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func MetricsMiddleware(svc http.Service, counter metrics.Counter, latency metric
|
||||
}
|
||||
}
|
||||
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, token string, msg messaging.Message) error {
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, token string, msg *messaging.Message) error {
|
||||
defer func(begin time.Time) {
|
||||
mm.counter.With("method", "publish").Add(1)
|
||||
mm.latency.With("method", "publish").Observe(time.Since(begin).Seconds())
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type publishReq struct {
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
token string
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func decodeRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
||||
defer r.Body.Close()
|
||||
|
||||
req := publishReq{
|
||||
msg: messaging.Message{
|
||||
msg: &messaging.Message{
|
||||
Protocol: protocol,
|
||||
Channel: bone.GetValue(r, "id"),
|
||||
Subtopic: subtopic,
|
||||
|
||||
@@ -14,7 +14,7 @@ func NewPublisher() messaging.Publisher {
|
||||
return mockPublisher{}
|
||||
}
|
||||
|
||||
func (pub mockPublisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub mockPublisher) Publish(topic string, msg *messaging.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -55,7 +55,7 @@ type Service interface {
|
||||
DisconnectThing(ctx context.Context, chanID, thingID string) error
|
||||
|
||||
// Publish forwards messages from the LoRa MQTT broker to Mainflux Message Broker
|
||||
Publish(ctx context.Context, msg Message) error
|
||||
Publish(ctx context.Context, msg *Message) error
|
||||
}
|
||||
|
||||
var _ Service = (*adapterService)(nil)
|
||||
@@ -78,7 +78,7 @@ func New(publisher messaging.Publisher, thingsRM, channelsRM, connectRM RouteMap
|
||||
}
|
||||
|
||||
// Publish forwards messages from Lora MQTT broker to Mainflux Message broker
|
||||
func (as *adapterService) Publish(ctx context.Context, m Message) error {
|
||||
func (as *adapterService) Publish(ctx context.Context, m *Message) error {
|
||||
// Get route map of lora application
|
||||
thingID, err := as.thingsRM.Get(ctx, m.DevEUI)
|
||||
if err != nil {
|
||||
@@ -122,7 +122,7 @@ func (as *adapterService) Publish(ctx context.Context, m Message) error {
|
||||
Created: time.Now().UnixNano(),
|
||||
}
|
||||
|
||||
return as.publisher.Publish(msg.Channel, msg)
|
||||
return as.publisher.Publish(msg.Channel, &msg)
|
||||
}
|
||||
|
||||
func (as *adapterService) CreateThing(ctx context.Context, thingID string, devEUI string) error {
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestPublish(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
err := svc.Publish(nil, tc.msg)
|
||||
err := svc.Publish(nil, &tc.msg)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ func (lm loggingMiddleware) DisconnectThing(ctx context.Context, chanID, thingID
|
||||
return lm.svc.DisconnectThing(ctx, chanID, thingID)
|
||||
}
|
||||
|
||||
func (lm loggingMiddleware) Publish(ctx context.Context, msg lora.Message) (err error) {
|
||||
func (lm loggingMiddleware) Publish(ctx context.Context, msg *lora.Message) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
message := fmt.Sprintf("publish application/%s/device/%s/rx took %s to complete", msg.ApplicationID, msg.DevEUI, time.Since(begin))
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ func (mm *metricsMiddleware) DisconnectThing(ctx context.Context, chanID, thingI
|
||||
return mm.svc.DisconnectThing(ctx, chanID, thingID)
|
||||
}
|
||||
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, msg lora.Message) error {
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, msg *lora.Message) error {
|
||||
defer func(begin time.Time) {
|
||||
mm.counter.With("method", "publish").Add(1)
|
||||
mm.latency.With("method", "publish").Observe(time.Since(begin).Seconds())
|
||||
|
||||
@@ -14,7 +14,7 @@ func NewPublisher() messaging.Publisher {
|
||||
return mockPublisher{}
|
||||
}
|
||||
|
||||
func (pub mockPublisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub mockPublisher) Publish(topic string, msg *messaging.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -54,5 +54,5 @@ func (b broker) handleMsg(c mqtt.Client, msg mqtt.Message) {
|
||||
return
|
||||
}
|
||||
|
||||
b.svc.Publish(context.Background(), m)
|
||||
b.svc.Publish(context.Background(), &m)
|
||||
}
|
||||
|
||||
+3
-3
@@ -41,7 +41,7 @@ func (f forwarder) Forward(id string, sub messaging.Subscriber, pub messaging.Pu
|
||||
}
|
||||
|
||||
func handle(pub messaging.Publisher, logger log.Logger) handleFunc {
|
||||
return func(msg messaging.Message) error {
|
||||
return func(msg *messaging.Message) error {
|
||||
if msg.Protocol == protocol {
|
||||
return nil
|
||||
}
|
||||
@@ -60,9 +60,9 @@ func handle(pub messaging.Publisher, logger log.Logger) handleFunc {
|
||||
}
|
||||
}
|
||||
|
||||
type handleFunc func(msg messaging.Message) error
|
||||
type handleFunc func(msg *messaging.Message) error
|
||||
|
||||
func (h handleFunc) Handle(msg messaging.Message) error {
|
||||
func (h handleFunc) Handle(msg *messaging.Message) error {
|
||||
return h(msg)
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ func (h *handler) Publish(c *session.Client, topic *string, payload *[]byte) {
|
||||
}
|
||||
|
||||
for _, pub := range h.publishers {
|
||||
if err := pub.Publish(msg.Channel, msg); err != nil {
|
||||
if err := pub.Publish(msg.Channel, &msg); err != nil {
|
||||
h.logger.Error(LogErrFailedPublishToMsgBroker + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ func NewPublisher() messaging.Publisher {
|
||||
return MockPublisher{}
|
||||
}
|
||||
|
||||
func (pub MockPublisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub MockPublisher) Publish(topic string, msg *messaging.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ func (c client) publish(ctx context.Context, token string, m message) error {
|
||||
Created: time.Now().UnixNano(),
|
||||
}
|
||||
|
||||
if err := c.publisher.Publish(msg.Channel, msg); err != nil {
|
||||
if err := c.publisher.Publish(msg.Channel, &msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+147
-524
@@ -1,572 +1,195 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// Copyright (c) Mainflux
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc v3.21.12
|
||||
// source: pkg/messaging/message.proto
|
||||
|
||||
package messaging
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
// 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
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
// Message represents a message emitted by the Mainflux adapters layer.
|
||||
type Message struct {
|
||||
Channel string `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"`
|
||||
Subtopic string `protobuf:"bytes,2,opt,name=subtopic,proto3" json:"subtopic,omitempty"`
|
||||
Publisher string `protobuf:"bytes,3,opt,name=publisher,proto3" json:"publisher,omitempty"`
|
||||
Protocol string `protobuf:"bytes,4,opt,name=protocol,proto3" json:"protocol,omitempty"`
|
||||
Payload []byte `protobuf:"bytes,5,opt,name=payload,proto3" json:"payload,omitempty"`
|
||||
Created int64 `protobuf:"varint,6,opt,name=created,proto3" json:"created,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Channel string `protobuf:"bytes,1,opt,name=channel,proto3" json:"channel,omitempty"`
|
||||
Subtopic string `protobuf:"bytes,2,opt,name=subtopic,proto3" json:"subtopic,omitempty"`
|
||||
Publisher string `protobuf:"bytes,3,opt,name=publisher,proto3" json:"publisher,omitempty"`
|
||||
Protocol string `protobuf:"bytes,4,opt,name=protocol,proto3" json:"protocol,omitempty"`
|
||||
Payload []byte `protobuf:"bytes,5,opt,name=payload,proto3" json:"payload,omitempty"`
|
||||
Created int64 `protobuf:"varint,6,opt,name=created,proto3" json:"created,omitempty"` // Unix timestamp in nanoseconds
|
||||
}
|
||||
|
||||
func (m *Message) Reset() { *m = Message{} }
|
||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||
func (*Message) ProtoMessage() {}
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_e5e29d24c44e4762, []int{0}
|
||||
func (x *Message) Reset() {
|
||||
*x = Message{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_pkg_messaging_message_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
func (m *Message) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
|
||||
func (x *Message) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_Message.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
func (*Message) ProtoMessage() {}
|
||||
|
||||
func (x *Message) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_pkg_messaging_message_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return b[:n], nil
|
||||
return ms
|
||||
}
|
||||
}
|
||||
func (m *Message) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Message.Merge(m, src)
|
||||
}
|
||||
func (m *Message) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *Message) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Message.DiscardUnknown(m)
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Message proto.InternalMessageInfo
|
||||
// Deprecated: Use Message.ProtoReflect.Descriptor instead.
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
return file_pkg_messaging_message_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (m *Message) GetChannel() string {
|
||||
if m != nil {
|
||||
return m.Channel
|
||||
func (x *Message) GetChannel() string {
|
||||
if x != nil {
|
||||
return x.Channel
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Message) GetSubtopic() string {
|
||||
if m != nil {
|
||||
return m.Subtopic
|
||||
func (x *Message) GetSubtopic() string {
|
||||
if x != nil {
|
||||
return x.Subtopic
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Message) GetPublisher() string {
|
||||
if m != nil {
|
||||
return m.Publisher
|
||||
func (x *Message) GetPublisher() string {
|
||||
if x != nil {
|
||||
return x.Publisher
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Message) GetProtocol() string {
|
||||
if m != nil {
|
||||
return m.Protocol
|
||||
func (x *Message) GetProtocol() string {
|
||||
if x != nil {
|
||||
return x.Protocol
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Message) GetPayload() []byte {
|
||||
if m != nil {
|
||||
return m.Payload
|
||||
func (x *Message) GetPayload() []byte {
|
||||
if x != nil {
|
||||
return x.Payload
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetCreated() int64 {
|
||||
if m != nil {
|
||||
return m.Created
|
||||
func (x *Message) GetCreated() int64 {
|
||||
if x != nil {
|
||||
return x.Created
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Message)(nil), "messaging.Message")
|
||||
}
|
||||
var File_pkg_messaging_message_proto protoreflect.FileDescriptor
|
||||
|
||||
func init() { proto.RegisterFile("pkg/messaging/message.proto", fileDescriptor_e5e29d24c44e4762) }
|
||||
|
||||
var fileDescriptor_e5e29d24c44e4762 = []byte{
|
||||
// 187 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0xc8, 0x4e, 0xd7,
|
||||
0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0xcf, 0xcc, 0x83, 0xb1, 0x52, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b,
|
||||
0xf2, 0x85, 0x38, 0xe1, 0x12, 0x4a, 0x6b, 0x19, 0xb9, 0xd8, 0x7d, 0x21, 0x92, 0x42, 0x12, 0x5c,
|
||||
0xec, 0xc9, 0x19, 0x89, 0x79, 0x79, 0xa9, 0x39, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x30,
|
||||
0xae, 0x90, 0x14, 0x17, 0x47, 0x71, 0x69, 0x52, 0x49, 0x7e, 0x41, 0x66, 0xb2, 0x04, 0x13, 0x58,
|
||||
0x0a, 0xce, 0x17, 0x92, 0xe1, 0xe2, 0x2c, 0x28, 0x4d, 0xca, 0xc9, 0x2c, 0xce, 0x48, 0x2d, 0x92,
|
||||
0x60, 0x06, 0x4b, 0x22, 0x04, 0x40, 0x3a, 0xc1, 0x76, 0x26, 0xe7, 0xe7, 0x48, 0xb0, 0x40, 0x74,
|
||||
0xc2, 0xf8, 0x20, 0xfb, 0x0a, 0x12, 0x2b, 0x73, 0xf2, 0x13, 0x53, 0x24, 0x58, 0x15, 0x18, 0x35,
|
||||
0x78, 0x82, 0x60, 0x5c, 0xb0, 0x4b, 0x8a, 0x52, 0x13, 0x4b, 0x52, 0x53, 0x24, 0xd8, 0x14, 0x18,
|
||||
0x35, 0x98, 0x83, 0x60, 0x5c, 0x27, 0x81, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c,
|
||||
0xf0, 0x48, 0x8e, 0x71, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0xb0, 0x79, 0xc6, 0x80, 0x00, 0x00,
|
||||
0x00, 0xff, 0xff, 0xa9, 0x1e, 0x4a, 0xea, 0xf2, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Message) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *Message) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.XXX_unrecognized != nil {
|
||||
i -= len(m.XXX_unrecognized)
|
||||
copy(dAtA[i:], m.XXX_unrecognized)
|
||||
}
|
||||
if m.Created != 0 {
|
||||
i = encodeVarintMessage(dAtA, i, uint64(m.Created))
|
||||
i--
|
||||
dAtA[i] = 0x30
|
||||
}
|
||||
if len(m.Payload) > 0 {
|
||||
i -= len(m.Payload)
|
||||
copy(dAtA[i:], m.Payload)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Payload)))
|
||||
i--
|
||||
dAtA[i] = 0x2a
|
||||
}
|
||||
if len(m.Protocol) > 0 {
|
||||
i -= len(m.Protocol)
|
||||
copy(dAtA[i:], m.Protocol)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Protocol)))
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
if len(m.Publisher) > 0 {
|
||||
i -= len(m.Publisher)
|
||||
copy(dAtA[i:], m.Publisher)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Publisher)))
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
if len(m.Subtopic) > 0 {
|
||||
i -= len(m.Subtopic)
|
||||
copy(dAtA[i:], m.Subtopic)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Subtopic)))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
if len(m.Channel) > 0 {
|
||||
i -= len(m.Channel)
|
||||
copy(dAtA[i:], m.Channel)
|
||||
i = encodeVarintMessage(dAtA, i, uint64(len(m.Channel)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintMessage(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovMessage(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *Message) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Channel)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMessage(uint64(l))
|
||||
}
|
||||
l = len(m.Subtopic)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMessage(uint64(l))
|
||||
}
|
||||
l = len(m.Publisher)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMessage(uint64(l))
|
||||
}
|
||||
l = len(m.Protocol)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMessage(uint64(l))
|
||||
}
|
||||
l = len(m.Payload)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMessage(uint64(l))
|
||||
}
|
||||
if m.Created != 0 {
|
||||
n += 1 + sovMessage(uint64(m.Created))
|
||||
}
|
||||
if m.XXX_unrecognized != nil {
|
||||
n += len(m.XXX_unrecognized)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovMessage(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozMessage(x uint64) (n int) {
|
||||
return sovMessage(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *Message) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: Message: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Channel", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Channel = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Subtopic", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Subtopic = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Publisher", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Publisher = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Protocol", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Protocol = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 5:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Payload = append(m.Payload[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Payload == nil {
|
||||
m.Payload = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 6:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Created", wireType)
|
||||
}
|
||||
m.Created = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Created |= int64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipMessage(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthMessage
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipMessage(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowMessage
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupMessage
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthMessage
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
var file_pkg_messaging_message_proto_rawDesc = []byte{
|
||||
0x0a, 0x1b, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x2f,
|
||||
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x6d,
|
||||
0x65, 0x73, 0x73, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x22, 0xad, 0x01, 0x0a, 0x07, 0x4d, 0x65, 0x73,
|
||||
0x73, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x1a,
|
||||
0x0a, 0x08, 0x73, 0x75, 0x62, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x08, 0x73, 0x75, 0x62, 0x74, 0x6f, 0x70, 0x69, 0x63, 0x12, 0x1c, 0x0a, 0x09, 0x70, 0x75,
|
||||
0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70,
|
||||
0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18,
|
||||
0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x18,
|
||||
0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, 0x0d, 0x5a, 0x0b, 0x2e, 0x2f, 0x6d, 0x65,
|
||||
0x73, 0x73, 0x61, 0x67, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupMessage = fmt.Errorf("proto: unexpected end of group")
|
||||
file_pkg_messaging_message_proto_rawDescOnce sync.Once
|
||||
file_pkg_messaging_message_proto_rawDescData = file_pkg_messaging_message_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_pkg_messaging_message_proto_rawDescGZIP() []byte {
|
||||
file_pkg_messaging_message_proto_rawDescOnce.Do(func() {
|
||||
file_pkg_messaging_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_messaging_message_proto_rawDescData)
|
||||
})
|
||||
return file_pkg_messaging_message_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_pkg_messaging_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_pkg_messaging_message_proto_goTypes = []interface{}{
|
||||
(*Message)(nil), // 0: messaging.Message
|
||||
}
|
||||
var file_pkg_messaging_message_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_pkg_messaging_message_proto_init() }
|
||||
func file_pkg_messaging_message_proto_init() {
|
||||
if File_pkg_messaging_message_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_pkg_messaging_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Message); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_pkg_messaging_message_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_pkg_messaging_message_proto_goTypes,
|
||||
DependencyIndexes: file_pkg_messaging_message_proto_depIdxs,
|
||||
MessageInfos: file_pkg_messaging_message_proto_msgTypes,
|
||||
}.Build()
|
||||
File_pkg_messaging_message_proto = out.File
|
||||
file_pkg_messaging_message_proto_rawDesc = nil
|
||||
file_pkg_messaging_message_proto_goTypes = nil
|
||||
file_pkg_messaging_message_proto_depIdxs = nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
syntax = "proto3";
|
||||
package messaging;
|
||||
|
||||
option go_package = "./messaging";
|
||||
|
||||
// Message represents a message emitted by the Mainflux adapters layer.
|
||||
message Message {
|
||||
string channel = 1;
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var errPublishTimeout = errors.New("failed to publish due to timeout reached")
|
||||
@@ -35,11 +35,11 @@ func NewPublisher(address string, timeout time.Duration) (messaging.Publisher, e
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (pub publisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub publisher) Publish(topic string, msg *messaging.Message) error {
|
||||
if topic == "" {
|
||||
return ErrEmptyTopic
|
||||
}
|
||||
data, err := proto.Marshal(&msg)
|
||||
data, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
log "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -199,7 +199,7 @@ func (ps *pubsub) mqttHandler(h messaging.MessageHandler) mqtt.MessageHandler {
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to unmarshal received message: %s", err))
|
||||
return
|
||||
}
|
||||
if err := h.Handle(msg); err != nil {
|
||||
if err := h.Handle(&msg); err != nil {
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to handle Mainflux message: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
mqtt_pubsub "github.com/mainflux/mainflux/pkg/messaging/mqtt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -63,7 +63,7 @@ func TestPublisher(t *testing.T) {
|
||||
})
|
||||
|
||||
// Test publish with an empty topic.
|
||||
err = pubsub.Publish("", messaging.Message{Payload: data})
|
||||
err = pubsub.Publish("", &messaging.Message{Payload: data})
|
||||
assert.Equal(t, err, mqtt_pubsub.ErrEmptyTopic, fmt.Sprintf("Publish with empty topic: expected: %s, got: %s", mqtt_pubsub.ErrEmptyTopic, err))
|
||||
|
||||
cases := []struct {
|
||||
@@ -104,7 +104,7 @@ func TestPublisher(t *testing.T) {
|
||||
Subtopic: tc.subtopic,
|
||||
Payload: tc.payload,
|
||||
}
|
||||
err := pubsub.Publish(topic, expectedMsg)
|
||||
err := pubsub.Publish(topic, &expectedMsg)
|
||||
assert.Nil(t, err, fmt.Sprintf("%s: got unexpected error: %s\n", tc.desc, err))
|
||||
|
||||
data, err := proto.Marshal(&expectedMsg)
|
||||
@@ -116,7 +116,7 @@ func TestPublisher(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubscribe(t *testing.T) {
|
||||
msgChan := make(chan messaging.Message)
|
||||
msgChan := make(chan *messaging.Message)
|
||||
|
||||
// Creating client to Publish messages to subscribed topic.
|
||||
client, err := newClient(address, "mainflux", brokerTimeout)
|
||||
@@ -203,13 +203,13 @@ func TestSubscribe(t *testing.T) {
|
||||
assert.Nil(t, token.Error(), fmt.Sprintf("got unexpected error: %s", token.Error()))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg, receivedMsg))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPubSub(t *testing.T) {
|
||||
msgChan := make(chan messaging.Message)
|
||||
msgChan := make(chan *messaging.Message)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -268,17 +268,17 @@ func TestPubSub(t *testing.T) {
|
||||
}
|
||||
|
||||
// Publish message, and then receive it on message channel.
|
||||
err := pubsub.Publish(topic, expectedMsg)
|
||||
err := pubsub.Publish(topic, &expectedMsg)
|
||||
assert.Nil(t, err, fmt.Sprintf("%s: got unexpected error: %s\n", tc.desc, err))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg, receivedMsg, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg.Payload, receivedMsg.Payload))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsubscribe(t *testing.T) {
|
||||
msgChan := make(chan messaging.Message)
|
||||
msgChan := make(chan *messaging.Message)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -424,10 +424,10 @@ func TestUnsubscribe(t *testing.T) {
|
||||
type handler struct {
|
||||
fail bool
|
||||
publisher string
|
||||
msgChan chan messaging.Message
|
||||
msgChan chan *messaging.Message
|
||||
}
|
||||
|
||||
func (h handler) Handle(msg messaging.Message) error {
|
||||
func (h handler) Handle(msg *messaging.Message) error {
|
||||
if msg.Publisher != h.publisher {
|
||||
h.msgChan <- msg
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ package nats
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
broker "github.com/nats-io/nats.go"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// A maximum number of reconnect attempts before NATS connection closes permanently.
|
||||
@@ -37,11 +37,11 @@ func NewPublisher(url string) (messaging.Publisher, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (pub *publisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub *publisher) Publish(topic string, msg *messaging.Message) error {
|
||||
if topic == "" {
|
||||
return ErrEmptyTopic
|
||||
}
|
||||
data, err := proto.Marshal(&msg)
|
||||
data, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
log "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
@@ -161,7 +161,7 @@ func (ps *pubsub) natsHandler(h messaging.MessageHandler) broker.MsgHandler {
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to unmarshal received message: %s", err))
|
||||
return
|
||||
}
|
||||
if err := h.Handle(msg); err != nil {
|
||||
if err := h.Handle(&msg); err != nil {
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to handle Mainflux message: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
msgChan = make(chan messaging.Message)
|
||||
msgChan = make(chan *messaging.Message)
|
||||
data = []byte("payload")
|
||||
errFailed = errors.New("failed")
|
||||
)
|
||||
@@ -74,11 +74,11 @@ func TestPublisher(t *testing.T) {
|
||||
}
|
||||
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
err = pubsub.Publish(topic, expectedMsg)
|
||||
err = pubsub.Publish(topic, &expectedMsg)
|
||||
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg, receivedMsg, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg.Payload, receivedMsg.Payload))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ type handler struct {
|
||||
fail bool
|
||||
}
|
||||
|
||||
func (h handler) Handle(msg messaging.Message) error {
|
||||
func (h handler) Handle(msg *messaging.Message) error {
|
||||
msgChan <- msg
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ package messaging
|
||||
// Publisher specifies message publishing API.
|
||||
type Publisher interface {
|
||||
// Publishes message to the stream.
|
||||
Publish(topic string, msg Message) error
|
||||
Publish(topic string, msg *Message) error
|
||||
|
||||
// Close gracefully closes message publisher's connection.
|
||||
Close() error
|
||||
@@ -15,7 +15,7 @@ type Publisher interface {
|
||||
// MessageHandler represents Message handler for Subscriber.
|
||||
type MessageHandler interface {
|
||||
// Handle handles messages passed by underlying implementation.
|
||||
Handle(msg Message) error
|
||||
Handle(msg *Message) error
|
||||
|
||||
// Cancel is used for cleanup during unsubscribing and it's optional.
|
||||
Cancel() error
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var _ messaging.Publisher = (*publisher)(nil)
|
||||
@@ -41,11 +41,11 @@ func NewPublisher(url string) (messaging.Publisher, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (pub *publisher) Publish(topic string, msg messaging.Message) error {
|
||||
func (pub *publisher) Publish(topic string, msg *messaging.Message) error {
|
||||
if topic == "" {
|
||||
return ErrEmptyTopic
|
||||
}
|
||||
data, err := proto.Marshal(&msg)
|
||||
data, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
log "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -167,7 +167,7 @@ func (ps *pubsub) handle(deliveries <-chan amqp.Delivery, h messaging.MessageHan
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to unmarshal received message: %s", err))
|
||||
return
|
||||
}
|
||||
if err := h.Handle(msg); err != nil {
|
||||
if err := h.Handle(&msg); err != nil {
|
||||
ps.logger.Warn(fmt.Sprintf("Failed to handle Mainflux message: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/mainflux/mainflux/pkg/messaging/rabbitmq"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -26,7 +26,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
msgChan = make(chan messaging.Message)
|
||||
msgChan = make(chan *messaging.Message)
|
||||
data = []byte("payload")
|
||||
)
|
||||
|
||||
@@ -87,11 +87,11 @@ func TestPublisher(t *testing.T) {
|
||||
Subtopic: tc.subtopic,
|
||||
Payload: tc.payload,
|
||||
}
|
||||
err = pubsub.Publish(topic, expectedMsg)
|
||||
err = pubsub.Publish(topic, &expectedMsg)
|
||||
assert.Nil(t, err, fmt.Sprintf("%s: got unexpected error: %s", tc.desc, err))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg, receivedMsg, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg.Payload, receivedMsg.Payload))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ func TestSubscribe(t *testing.T) {
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg, receivedMsg))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,11 +402,11 @@ func TestPubSub(t *testing.T) {
|
||||
Payload: data,
|
||||
}
|
||||
|
||||
err = pubsub.Publish(tc.topic, expectedMsg)
|
||||
err = pubsub.Publish(tc.topic, &expectedMsg)
|
||||
assert.Nil(t, err, fmt.Sprintf("%s got unexpected error: %s", tc.desc, err))
|
||||
|
||||
receivedMsg := <-msgChan
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, expectedMsg, receivedMsg))
|
||||
assert.Equal(t, expectedMsg.Payload, receivedMsg.Payload, fmt.Sprintf("%s: expected %+v got %+v\n", tc.desc, &expectedMsg, receivedMsg))
|
||||
|
||||
err = pubsub.Unsubscribe(tc.clientID, fmt.Sprintf("%s.%s", chansPrefix, tc.topic))
|
||||
assert.Nil(t, err, fmt.Sprintf("%s got unexpected error: %s", tc.desc, err))
|
||||
@@ -421,7 +421,7 @@ type handler struct {
|
||||
publisher string
|
||||
}
|
||||
|
||||
func (h handler) Handle(msg messaging.Message) error {
|
||||
func (h handler) Handle(msg *messaging.Message) error {
|
||||
if msg.Publisher != h.publisher {
|
||||
msgChan <- msg
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
mflog "github.com/mainflux/mainflux/logger"
|
||||
"github.com/mainflux/mainflux/pkg/messaging"
|
||||
"github.com/mainflux/mainflux/pkg/messaging/rabbitmq"
|
||||
dockertest "github.com/ory/dockertest/v3"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -95,7 +95,7 @@ func rabbitHandler(deliveries <-chan amqp.Delivery, h messaging.MessageHandler)
|
||||
logger.Warn(fmt.Sprintf("Failed to unmarshal received message: %s", err))
|
||||
return
|
||||
}
|
||||
if err := h.Handle(msg); err != nil {
|
||||
if err := h.Handle(&msg); err != nil {
|
||||
logger.Warn(fmt.Sprintf("Failed to handle Mainflux message: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func New(tfs []TimeField) transformers.Transformer {
|
||||
}
|
||||
|
||||
// Transform transforms Mainflux message to a list of JSON messages.
|
||||
func (ts *transformerService) Transform(msg messaging.Message) (interface{}, error) {
|
||||
func (ts *transformerService) Transform(msg *messaging.Message) (interface{}, error) {
|
||||
ret := Message{
|
||||
Publisher: msg.Publisher,
|
||||
Created: msg.Created,
|
||||
|
||||
@@ -43,23 +43,59 @@ func TestTransformJSON(t *testing.T) {
|
||||
Payload: []byte(validPayload),
|
||||
Created: now,
|
||||
}
|
||||
invalid := msg
|
||||
invalid.Payload = []byte(invalidPayload)
|
||||
invalid := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "subtopic-1",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(invalidPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
listMsg := msg
|
||||
listMsg.Payload = []byte(listPayload)
|
||||
listMsg := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "subtopic-1",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(listPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
tsMsg := msg
|
||||
tsMsg.Payload = []byte(tsPayload)
|
||||
tsMsg := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "subtopic-1",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(tsPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
microsMsg := msg
|
||||
microsMsg.Payload = []byte(microsPayload)
|
||||
microsMsg := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "subtopic-1",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(microsPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
invalidFmt := msg
|
||||
invalidFmt.Subtopic = ""
|
||||
invalidFmt := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(validPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
invalidTimeField := msg
|
||||
invalidTimeField.Payload = []byte(invalidTsPayload)
|
||||
invalidTimeField := messaging.Message{
|
||||
Channel: "channel-1",
|
||||
Subtopic: "subtopic-1",
|
||||
Publisher: "publisher-1",
|
||||
Protocol: "protocol",
|
||||
Payload: []byte(invalidTsPayload),
|
||||
Created: now,
|
||||
}
|
||||
|
||||
jsonMsgs := json.Messages{
|
||||
Data: []json.Message{
|
||||
@@ -164,49 +200,49 @@ func TestTransformJSON(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
json interface{}
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "test transform JSON",
|
||||
msg: msg,
|
||||
msg: &msg,
|
||||
json: jsonMsgs,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON with an invalid subtopic",
|
||||
msg: invalidFmt,
|
||||
msg: &invalidFmt,
|
||||
json: nil,
|
||||
err: json.ErrTransform,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON array",
|
||||
msg: listMsg,
|
||||
msg: &listMsg,
|
||||
json: listJSON,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON with invalid payload",
|
||||
msg: invalid,
|
||||
msg: &invalid,
|
||||
json: nil,
|
||||
err: json.ErrTransform,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON with timestamp transformation",
|
||||
msg: tsMsg,
|
||||
msg: &tsMsg,
|
||||
json: jsonTsMsgs,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON with timestamp transformation in micros",
|
||||
msg: microsMsg,
|
||||
msg: µsMsg,
|
||||
json: jsonMicrosMsgs,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "test transform JSON with invalid timestamp transformation in micros",
|
||||
msg: invalidTimeField,
|
||||
msg: &invalidTimeField,
|
||||
json: nil,
|
||||
err: json.ErrInvalidTimeField,
|
||||
},
|
||||
|
||||
@@ -43,7 +43,7 @@ func New(contentFormat string) transformers.Transformer {
|
||||
}
|
||||
}
|
||||
|
||||
func (t transformer) Transform(msg messaging.Message) (interface{}, error) {
|
||||
func (t transformer) Transform(msg *messaging.Message) (interface{}, error) {
|
||||
raw, err := senml.Decode(msg.Payload, t.format)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errDecode, err)
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestTransformJSON(t *testing.T) {
|
||||
require.Nil(t, err, "Decoding JSON expected to succeed")
|
||||
|
||||
tr := senml.New(senml.JSON)
|
||||
msg := messaging.Message{
|
||||
msg := &messaging.Message{
|
||||
Channel: "channel",
|
||||
Subtopic: "subtopic",
|
||||
Publisher: "publisher",
|
||||
@@ -32,8 +32,6 @@ func TestTransformJSON(t *testing.T) {
|
||||
Payload: jsonBytes,
|
||||
}
|
||||
|
||||
// 82AD2169626173652D6E616D6522F956402369626173652D756E6974200A24F9490025F9564000646E616D650164756E697406F95CB0036331323307F958B002F9514005F94900AA2169626173652D6E616D6522F956402369626173652D756E6974200A24F9490025F9564000646E616D6506F95CB007F958B005F94900
|
||||
|
||||
jsonPld := msg
|
||||
jsonPld.Payload = jsonBytes
|
||||
|
||||
@@ -56,7 +54,7 @@ func TestTransformJSON(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
msgs interface{}
|
||||
err error
|
||||
}{
|
||||
@@ -92,7 +90,8 @@ func TestTransformCBOR(t *testing.T) {
|
||||
require.Nil(t, err, "Decoding CBOR expected to succeed")
|
||||
|
||||
tr := senml.New(senml.CBOR)
|
||||
msg := messaging.Message{
|
||||
|
||||
cborPld := &messaging.Message{
|
||||
Channel: "channel",
|
||||
Subtopic: "subtopic",
|
||||
Publisher: "publisher",
|
||||
@@ -100,13 +99,13 @@ func TestTransformCBOR(t *testing.T) {
|
||||
Payload: cborBytes,
|
||||
}
|
||||
|
||||
// 82AD2169626173652D6E616D6522F956402369626173652D756E6974200A24F9490025F9564000646E616D650164756E697406F95CB0036331323307F958B002F9514005F94900AA2169626173652D6E616D6522F956402369626173652D756E6974200A24F9490025F9564000646E616D6506F95CB007F958B005F94900
|
||||
|
||||
cborPld := msg
|
||||
cborPld.Payload = cborBytes
|
||||
|
||||
tooManyMsg := msg
|
||||
tooManyMsg.Payload = tooManyBytes
|
||||
tooManyMsg := &messaging.Message{
|
||||
Channel: "channel",
|
||||
Subtopic: "subtopic",
|
||||
Publisher: "publisher",
|
||||
Protocol: "protocol",
|
||||
Payload: tooManyBytes,
|
||||
}
|
||||
|
||||
val := 52.0
|
||||
sum := 110.0
|
||||
@@ -127,7 +126,7 @@ func TestTransformCBOR(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
msgs interface{}
|
||||
err error
|
||||
}{
|
||||
|
||||
@@ -8,5 +8,5 @@ import "github.com/mainflux/mainflux/pkg/messaging"
|
||||
// Transformer specifies API form Message transformer.
|
||||
type Transformer interface {
|
||||
// Transform Mainflux message to any other format.
|
||||
Transform(msg messaging.Message) (interface{}, error)
|
||||
Transform(msg *messaging.Message) (interface{}, error)
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
# This script contains commands to be executed by the CI tool.
|
||||
NPROC=$(nproc)
|
||||
GO_VERSION=1.19.4
|
||||
PROTOC_VERSION=3.12.3
|
||||
PROTOC_GEN_VERSION=v1.4.2
|
||||
PROTOC_GOFAST_VERSION=v1.3.1
|
||||
PROTOC_VERSION=21.12
|
||||
PROTOC_GEN_VERSION=v1.28.1
|
||||
PROTOC_GRPC_VERSION=v1.2.0
|
||||
|
||||
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
|
||||
|
||||
@@ -37,8 +37,8 @@ setup_protoc() {
|
||||
sudo mv protoc3/include/* /usr/local/include/
|
||||
rm -f PROTOC_ZIP
|
||||
|
||||
go install github.com/golang/protobuf/protoc-gen-go@$PROTOC_GEN_VERSION
|
||||
go install github.com/gogo/protobuf/protoc-gen-gofast@$PROTOC_GOFAST_VERSION
|
||||
go install google.golang.org/protobuf/cmd/protoc-gen-go@$PROTOC_GEN_VERSION
|
||||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$PROTOC_GRPC_VERSION
|
||||
|
||||
export PATH=$PATH:/usr/local/bin/protoc
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type grpcServer struct {
|
||||
canAccessByID kitgrpc.Handler
|
||||
isChannelOwner kitgrpc.Handler
|
||||
identify kitgrpc.Handler
|
||||
mainflux.UnimplementedThingsServiceServer
|
||||
}
|
||||
|
||||
// NewServer returns new ThingsServiceServer instance.
|
||||
|
||||
@@ -21,7 +21,7 @@ func NewBroker(sub map[string]string) messaging.Publisher {
|
||||
}
|
||||
}
|
||||
|
||||
func (mb mockBroker) Publish(topic string, msg messaging.Message) error {
|
||||
func (mb mockBroker) Publish(topic string, msg *messaging.Message) error {
|
||||
if len(msg.Payload) == 0 {
|
||||
return errors.New("failed to publish")
|
||||
}
|
||||
|
||||
+1
-1
@@ -421,7 +421,7 @@ func (ts *twinsService) publish(twinID *string, err *error, succOp, failOp strin
|
||||
Created: time.Now().UnixNano(),
|
||||
}
|
||||
|
||||
if err := ts.publisher.Publish(msg.Channel, msg); err != nil {
|
||||
if err := ts.publisher.Publish(msg.Channel, &msg); err != nil {
|
||||
ts.logger.Warn(fmt.Sprintf("Failed to publish notification on Message Broker: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -48,7 +48,7 @@ var (
|
||||
// Service specifies web socket service API.
|
||||
type Service interface {
|
||||
// Publish Message
|
||||
Publish(ctx context.Context, thingKey string, msg messaging.Message) error
|
||||
Publish(ctx context.Context, thingKey string, msg *messaging.Message) error
|
||||
|
||||
// Subscribes to a channel with specified id.
|
||||
Subscribe(ctx context.Context, thingKey, chanID, subtopic string, client *Client) error
|
||||
@@ -73,7 +73,7 @@ func New(auth mainflux.ThingsServiceClient, pubsub messaging.PubSub) Service {
|
||||
}
|
||||
|
||||
// Publish publishes the message using the broker
|
||||
func (svc *adapterService) Publish(ctx context.Context, thingKey string, msg messaging.Message) error {
|
||||
func (svc *adapterService) Publish(ctx context.Context, thingKey string, msg *messaging.Message) error {
|
||||
thid, err := svc.authorize(ctx, thingKey, msg.GetChannel())
|
||||
if err != nil {
|
||||
return ErrUnauthorizedAccess
|
||||
|
||||
+7
-7
@@ -44,43 +44,43 @@ func TestPublish(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
thingKey string
|
||||
msg messaging.Message
|
||||
msg *messaging.Message
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "publish a valid message with valid thingKey",
|
||||
thingKey: thingKey,
|
||||
msg: msg,
|
||||
msg: &msg,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "publish a valid message with empty thingKey",
|
||||
thingKey: "",
|
||||
msg: msg,
|
||||
msg: &msg,
|
||||
err: ws.ErrUnauthorizedAccess,
|
||||
},
|
||||
{
|
||||
desc: "publish a valid message with invalid thingKey",
|
||||
thingKey: "invalid",
|
||||
msg: msg,
|
||||
msg: &msg,
|
||||
err: ws.ErrUnauthorizedAccess,
|
||||
},
|
||||
{
|
||||
desc: "publish an empty message with valid thingKey",
|
||||
thingKey: thingKey,
|
||||
msg: messaging.Message{},
|
||||
msg: &messaging.Message{},
|
||||
err: ws.ErrFailedMessagePublish,
|
||||
},
|
||||
{
|
||||
desc: "publish an empty message with empty thingKey",
|
||||
thingKey: "",
|
||||
msg: messaging.Message{},
|
||||
msg: &messaging.Message{},
|
||||
err: ws.ErrUnauthorizedAccess,
|
||||
},
|
||||
{
|
||||
desc: "publish an empty message with invalid thingKey",
|
||||
thingKey: "invalid",
|
||||
msg: messaging.Message{},
|
||||
msg: &messaging.Message{},
|
||||
err: ws.ErrUnauthorizedAccess,
|
||||
},
|
||||
}
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ func process(svc ws.Service, req connReq, msgs <-chan []byte) {
|
||||
Payload: msg,
|
||||
Created: time.Now().UnixNano(),
|
||||
}
|
||||
svc.Publish(context.Background(), req.thingKey, m)
|
||||
svc.Publish(context.Background(), req.thingKey, &m)
|
||||
}
|
||||
if err := svc.Unsubscribe(context.Background(), req.thingKey, req.chanID, req.subtopic); err != nil {
|
||||
req.conn.Close()
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ func LoggingMiddleware(svc ws.Service, logger log.Logger) ws.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, thingKey string, msg messaging.Message) (err error) {
|
||||
func (lm *loggingMiddleware) Publish(ctx context.Context, thingKey string, msg *messaging.Message) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
destChannel := msg.GetChannel()
|
||||
if msg.Subtopic != "" {
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func MetricsMiddleware(svc ws.Service, counter metrics.Counter, latency metrics.
|
||||
}
|
||||
}
|
||||
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, thingKey string, msg messaging.Message) error {
|
||||
func (mm *metricsMiddleware) Publish(ctx context.Context, thingKey string, msg *messaging.Message) error {
|
||||
defer func(begin time.Time) {
|
||||
mm.counter.With("method", "publish").Add(1)
|
||||
mm.latency.With("method", "publish").Observe(time.Since(begin).Seconds())
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ func (c *Client) Cancel() error {
|
||||
}
|
||||
|
||||
// Handle handles the sending and receiving of messages via the broker
|
||||
func (c *Client) Handle(msg messaging.Message) error {
|
||||
func (c *Client) Handle(msg *messaging.Message) error {
|
||||
// To prevent publisher from receiving its own published message
|
||||
if msg.GetPublisher() == c.id {
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ func TestHandle(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
msg.Publisher = tc.publisher
|
||||
err = c.Handle(msg)
|
||||
err = c.Handle(&msg)
|
||||
assert.Nil(t, err, fmt.Sprintf("expected nil error from handle, got: %s", err))
|
||||
receivedMsg := []byte{}
|
||||
switch tc.expectMsg {
|
||||
@@ -94,7 +94,7 @@ func TestHandle(t *testing.T) {
|
||||
case false:
|
||||
time.Sleep(100 * time.Millisecond) // Give time to server to process c.Handle call.
|
||||
}
|
||||
assert.Equal(t, tc.expectedPayload, receivedMsg, fmt.Sprintf("%s: expected %+v, got %+v", tc.desc, msg, receivedMsg))
|
||||
assert.Equal(t, tc.expectedPayload, receivedMsg, fmt.Sprintf("%s: expected %+v, got %+v", tc.desc, &msg, receivedMsg))
|
||||
}
|
||||
c := atomic.LoadUint64(&count)
|
||||
assert.Equal(t, expectedCount, c, fmt.Sprintf("expected message count %d, got %d", expectedCount, c))
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import (
|
||||
var _ messaging.PubSub = (*mockPubSub)(nil)
|
||||
|
||||
type MockPubSub interface {
|
||||
Publish(string, messaging.Message) error
|
||||
Publish(string, *messaging.Message) error
|
||||
Subscribe(string, string, messaging.MessageHandler) error
|
||||
Unsubscribe(string, string) error
|
||||
SetFail(bool)
|
||||
@@ -32,7 +32,7 @@ type mockPubSub struct {
|
||||
func NewPubSub() MockPubSub {
|
||||
return &mockPubSub{false, nil}
|
||||
}
|
||||
func (pubsub *mockPubSub) Publish(s string, msg messaging.Message) error {
|
||||
func (pubsub *mockPubSub) Publish(s string, msg *messaging.Message) error {
|
||||
if pubsub.conn != nil {
|
||||
data, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user