NOISSUE - Fix default nats pubsub subject (#1153)

* NOISSUE - Fix default nats publisher subject

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Use created timestamp inn transformer

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Use created timestamp in transformer

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* rename topic -> subject for nats

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* revert

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* revert

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix subscriber topic

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix timestamp

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Use int64 nanoseconds Created timestamp

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Typo

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Add comment to created protobuf field

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Rm gogo from scripts/ci.sh

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Fix comment

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>

* Return publisher in NewPublisher

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
Manuel Imperiale
2020-05-04 13:14:06 +02:00
committed by GitHub
parent 0c016cd7ce
commit 2b4cf8a990
13 changed files with 496 additions and 93 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ test:
proto:
protoc --gofast_out=plugins=grpc:. *.proto
protoc --gogo_out=plugins=grpc:. messaging/*.proto
protoc --gofast_out=plugins=grpc:. messaging/*.proto
$(SERVICES):
$(call compile_service,$(@))
+1 -7
View File
@@ -18,7 +18,6 @@ import (
gocoap "github.com/dustin/go-coap"
"github.com/go-zoo/bone"
"github.com/golang/protobuf/ptypes"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/coap"
log "github.com/mainflux/mainflux/logger"
@@ -225,18 +224,13 @@ func receive(svc coap.Service, msg *gocoap.Message) *gocoap.Message {
return res
}
created, err := ptypes.TimestampProto(time.Now())
if err != nil {
return nil
}
m := messaging.Message{
Channel: chanID,
Subtopic: subtopic,
Publisher: publisher,
Protocol: protocol,
Payload: msg.Payload,
Created: created,
Created: time.Now().UnixNano(),
}
if err := svc.Publish(m); err != nil {
+1 -7
View File
@@ -17,7 +17,6 @@ import (
kitot "github.com/go-kit/kit/tracing/opentracing"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/go-zoo/bone"
"github.com/golang/protobuf/ptypes"
"github.com/mainflux/mainflux"
adapter "github.com/mainflux/mainflux/http"
"github.com/mainflux/mainflux/messaging"
@@ -110,17 +109,12 @@ func decodeRequest(ctx context.Context, r *http.Request) (interface{}, error) {
return nil, err
}
created, err := ptypes.TimestampProto(time.Now())
if err != nil {
return nil, err
}
msg := messaging.Message{
Protocol: protocol,
Channel: chanID,
Subtopic: subtopic,
Payload: payload,
Created: created,
Created: time.Now().UnixNano(),
}
req := publishReq{
+1 -7
View File
@@ -7,7 +7,6 @@ import (
"errors"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/mainflux/mainflux/messaging"
)
@@ -101,18 +100,13 @@ func (as *adapterService) Publish(ctx context.Context, token string, m Message)
payload = []byte(jo)
}
created, err := ptypes.TimestampProto(time.Now())
if err != nil {
return nil
}
// Publish on Mainflux NATS broker
msg := messaging.Message{
Publisher: thing,
Protocol: protocol,
Channel: channel,
Payload: payload,
Created: created,
Created: time.Now().UnixNano(),
}
return as.publisher.Publish(msg.Channel, msg)
+479 -31
View File
@@ -5,9 +5,10 @@ package messaging
import (
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
proto "github.com/golang/protobuf/proto"
io "io"
math "math"
math_bits "math/bits"
)
// Reference imports to suppress errors if they are not otherwise used.
@@ -19,19 +20,19 @@ var _ = math.Inf
// 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.GoGoProtoPackageIsVersion3 // please upgrade the proto package
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// 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 *timestamp.Timestamp `protobuf:"bytes,6,opt,name=created,proto3" json:"created,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
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:"-"`
}
func (m *Message) Reset() { *m = Message{} }
@@ -41,16 +42,25 @@ func (*Message) Descriptor() ([]byte, []int) {
return fileDescriptor_77305e42dfa8cc5b, []int{0}
}
func (m *Message) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Message.Unmarshal(m, b)
return m.Unmarshal(b)
}
func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Message.Marshal(b, m, deterministic)
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
}
return b[:n], nil
}
}
func (m *Message) XXX_Merge(src proto.Message) {
xxx_messageInfo_Message.Merge(m, src)
}
func (m *Message) XXX_Size() int {
return xxx_messageInfo_Message.Size(m)
return m.Size()
}
func (m *Message) XXX_DiscardUnknown() {
xxx_messageInfo_Message.DiscardUnknown(m)
@@ -93,11 +103,11 @@ func (m *Message) GetPayload() []byte {
return nil
}
func (m *Message) GetCreated() *timestamp.Timestamp {
func (m *Message) GetCreated() int64 {
if m != nil {
return m.Created
}
return nil
return 0
}
func init() {
@@ -107,18 +117,456 @@ func init() {
func init() { proto.RegisterFile("messaging/message.proto", fileDescriptor_77305e42dfa8cc5b) }
var fileDescriptor_77305e42dfa8cc5b = []byte{
// 202 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x8f, 0xcd, 0x8e, 0x83, 0x20,
0x14, 0x85, 0xc3, 0xfc, 0xe8, 0xc8, 0xcc, 0x8a, 0xcd, 0x10, 0x33, 0xc9, 0x98, 0xae, 0x5c, 0x61,
0xd2, 0xf6, 0x35, 0xba, 0x31, 0x7d, 0x01, 0xc0, 0x5b, 0x24, 0x41, 0x21, 0x82, 0x8b, 0x3e, 0x62,
0xdf, 0xaa, 0x11, 0x82, 0xdd, 0xf1, 0xf1, 0xdd, 0x93, 0x93, 0x83, 0x7f, 0x27, 0xf0, 0x9e, 0x2b,
0x3d, 0xab, 0x2e, 0xbd, 0x80, 0xb9, 0xc5, 0x06, 0x4b, 0xaa, 0x5d, 0xd4, 0xff, 0xca, 0x5a, 0x65,
0xa0, 0x8b, 0x42, 0xac, 0xb7, 0x2e, 0xe8, 0x09, 0x7c, 0xe0, 0x93, 0x4b, 0xb7, 0x87, 0x07, 0xc2,
0xe5, 0x25, 0xa5, 0x09, 0xc5, 0xa5, 0x1c, 0xf9, 0x3c, 0x83, 0xa1, 0xa8, 0x41, 0x6d, 0xd5, 0x67,
0x24, 0x35, 0xfe, 0xf2, 0xab, 0x08, 0xd6, 0x69, 0x49, 0xdf, 0xa2, 0xda, 0x99, 0xfc, 0xe1, 0xca,
0xad, 0xc2, 0x68, 0x3f, 0xc2, 0x42, 0xdf, 0xa3, 0x7c, 0x7d, 0x6c, 0xc9, 0x58, 0x24, 0xad, 0xa1,
0x1f, 0x29, 0x99, 0x79, 0xeb, 0x73, 0xfc, 0x6e, 0x2c, 0x1f, 0xe8, 0x67, 0x83, 0xda, 0x9f, 0x3e,
0x23, 0x39, 0xe3, 0x52, 0x2e, 0xc0, 0x03, 0x0c, 0xb4, 0x68, 0x50, 0xfb, 0x7d, 0xac, 0x59, 0x1a,
0xc2, 0xf2, 0x10, 0x76, 0xcd, 0x43, 0xfa, 0x7c, 0x2a, 0x8a, 0x28, 0x4f, 0xcf, 0x00, 0x00, 0x00,
0xff, 0xff, 0x30, 0x7a, 0x2f, 0x67, 0x19, 0x01, 0x00, 0x00,
// 185 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0x4d, 0x2d, 0x2e,
0x4e, 0x4c, 0xcf, 0xcc, 0x4b, 0xd7, 0x87, 0xb0, 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, 0x97, 0x94, 0x8c, 0x50, 0xee, 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 (
ErrInvalidLengthMessage = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowMessage = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupMessage = fmt.Errorf("proto: unexpected end of group")
)
+6 -7
View File
@@ -3,14 +3,13 @@
syntax = "proto3";
package messaging;
import "google/protobuf/timestamp.proto";
// Message represents a message emitted by the Mainflux adapters layer.
message Message {
string channel = 1;
string subtopic = 2;
string publisher = 3;
string protocol = 4;
bytes payload = 5;
google.protobuf.Timestamp created = 6;
string channel = 1;
string subtopic = 2;
string publisher = 3;
string protocol = 4;
bytes payload = 5;
int64 created = 6; // Unix timestamp in nanoseconds
}
+1 -1
View File
@@ -30,7 +30,7 @@ func NewPublisher(url string) (Publisher, error) {
if err != nil {
return nil, err
}
ret := &pubsub{
ret := &publisher{
conn: conn,
}
return ret, nil
+1 -3
View File
@@ -91,7 +91,7 @@ func (ps *pubsub) Subscribe(topic string, handler messaging.MessageHandler) erro
return errAlreadySubscribed
}
nh := ps.natsHandler(handler)
topic = fmt.Sprintf("%s.%s", chansPrefix, topic)
if ps.queue != "" {
sub, err := ps.conn.QueueSubscribe(topic, ps.queue, nh)
if err != nil {
@@ -115,8 +115,6 @@ func (ps *pubsub) Unsubscribe(topic string) error {
ps.mu.Lock()
defer ps.mu.Unlock()
topic = fmt.Sprintf("%s.%s", chansPrefix, topic)
sub, ok := ps.subscriptions[topic]
if !ok {
return errNotSubscribed
+1 -8
View File
@@ -11,7 +11,6 @@ import (
"strings"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/messaging"
@@ -151,19 +150,13 @@ func (h *handler) Publish(c *session.Client, topic *string, payload *[]byte) {
return
}
created, err := ptypes.TimestampProto(time.Now())
if err != nil {
h.logger.Info("Error creating message timestamp: " + err.Error())
return
}
msg := messaging.Message{
Protocol: protocol,
Channel: chanID,
Subtopic: subtopic,
Publisher: c.Username,
Payload: *payload,
Created: created,
Created: time.Now().UnixNano(),
}
for _, pub := range h.publishers {
+1 -7
View File
@@ -9,7 +9,6 @@ import (
"strconv"
"time"
"github.com/golang/protobuf/ptypes"
opcuaGopcua "github.com/gopcua/opcua"
uaGopcua "github.com/gopcua/opcua/ua"
"github.com/mainflux/mainflux/errors"
@@ -219,11 +218,6 @@ func (c client) publish(token string, m message) error {
return errNotFoundNodeID
}
created, err := ptypes.TimestampProto(time.Now())
if err != nil {
return nil
}
// Check connection between ServerURI and NodeID
cKey := fmt.Sprintf("%s:%s", chanID, thingID)
if _, err := c.connectRM.Get(cKey); err != nil {
@@ -240,7 +234,7 @@ func (c client) publish(token string, m message) error {
Channel: chanID,
Payload: payload,
Subtopic: m.NodeID,
Created: created,
Created: time.Now().UnixNano(),
}
if err := c.publisher.Publish(msg.Channel, msg); err != nil {
-4
View File
@@ -4,8 +4,6 @@ GO_VERSION=1.13
PROTOC_VERSION=3.11.4
PROTOC_GEN_VERSION=v1.3.3
PROTOC_GOFAST_VERSION=v1.3.1
PROTOC_GOGO_VERSION=v1.3.1
GOGOPROTO_VERSION=v1.3.1
GRPC_VERSION=v1.27.1
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
@@ -43,9 +41,7 @@ setup_protoc() {
rm -f PROTOC_ZIP
go get -u github.com/golang/protobuf/protoc-gen-go@$PROTOC_GEN_VERSION \
github.com/gogo/protobuf/protoc-gen-gogo@$PROTOC_GOGO_VERSION \
github.com/gogo/protobuf/protoc-gen-gofast@$PROTOC_GOFAST_VERSION \
github.com/gogo/protobuf/gogoproto@$GOGOPROTO_VERSION \
google.golang.org/grpc@$GRPC_VERSION
export PATH=$PATH:/usr/local/bin/protoc
+2 -3
View File
@@ -4,8 +4,6 @@
package senml
import (
"time"
"github.com/mainflux/mainflux/errors"
"github.com/mainflux/mainflux/messaging"
"github.com/mainflux/mainflux/transformers"
@@ -61,7 +59,8 @@ func (t transformer) Transform(msg messaging.Message) (interface{}, error) {
// Use reception timestamp if SenML messsage Time is missing
t := v.Time
if t == 0 {
t = float64(time.Now().UnixNano())
// Convert the Unix timestamp in nanoseconds to float64
t = float64(msg.Created) / float64(1e9)
}
msgs[i] = Message{
+1 -7
View File
@@ -10,7 +10,6 @@ import (
"math"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/mainflux/mainflux/errors"
"github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/messaging"
@@ -428,17 +427,12 @@ func (ts *twinsService) publish(twinID *string, err *error, succOp, failOp strin
pl = []byte(fmt.Sprintf("{\"deleted\":\"%s\"}", *twinID))
}
created, timeErr := ptypes.TimestampProto(time.Now())
if timeErr != nil {
return
}
msg := messaging.Message{
Channel: ts.channelID,
Subtopic: op,
Payload: pl,
Publisher: publisher,
Created: created,
Created: time.Now().UnixNano(),
}
if err := ts.publisher.Publish(msg.Channel, msg); err != nil {