Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Create broker package for NATS #1080

Merged
merged 27 commits into from
Apr 1, 2020
Merged

NOISSUE - Create broker package for NATS #1080

merged 27 commits into from
Apr 1, 2020

Conversation

manuio
Copy link
Contributor

@manuio manuio commented Mar 20, 2020

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

@manuio manuio requested a review from a team as a code owner March 20, 2020 07:57
@drasko drasko changed the title NOISSUEE - Create broker package for NATS NOISSUE - Create broker package for NATS Mar 20, 2020
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
brokers/brokers.go Outdated Show resolved Hide resolved
brokers/brokers.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
brokers/nats/subscribe.go Outdated Show resolved Hide resolved
brokers/brokers.go Outdated Show resolved Hide resolved
brokers/brokers.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
brokers/nats/subscribe.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
brokers/nats/publish.go Outdated Show resolved Hide resolved
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
coap/adapter.go Outdated Show resolved Hide resolved
ws/adapter.go Outdated Show resolved Hide resolved
coap/adapter.go Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Mar 21, 2020

Codecov Report

Merging #1080 into master will decrease coverage by 0.11%.
The diff coverage is 65.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1080      +/-   ##
==========================================
- Coverage   77.21%   77.10%   -0.12%     
==========================================
  Files          95       95              
  Lines        6921     6760     -161     
==========================================
- Hits         5344     5212     -132     
+ Misses       1238     1211      -27     
+ Partials      339      337       -2     
Impacted Files Coverage Δ
readers/influxdb/messages.go 76.92% <ø> (ø)
ws/adapter.go 67.34% <44.44%> (-11.45%) ⬇️
twins/service.go 42.23% <76.47%> (-5.22%) ⬇️
http/api/endpoint.go 100.00% <100.00%> (ø)
http/api/transport.go 74.39% <100.00%> (-0.40%) ⬇️
transformers/senml/transformer.go 93.10% <100.00%> (ø)
ws/api/transport.go 80.46% <100.00%> (-6.09%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51ec256...a8efe61. Read the comment docs.

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
cmd/coap/main.go Outdated Show resolved Hide resolved
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
drasko
drasko previously approved these changes Mar 28, 2020
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

drasko
drasko previously approved these changes Mar 30, 2020
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
broker/broker.go Outdated Show resolved Hide resolved
@@ -36,7 +36,7 @@ type Observer struct {
// NewObserver instantiates a new Observer.
func NewObserver() *Observer {
return &Observer{
Messages: make(chan mainflux.Message),
Messages: make(chan broker.Message),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we expired and msgID should be in its own structure with its own mutex, and Observer can embed those structures.
Also wouldnt be better that Observer is interface?

}

go func() {
<-o.Cancel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong but seems that wait group fits here, us if you can, it is faster.

// Service specifies coap service API.
type Service interface {
// Publish Messssage
Publish(context.Context, string, broker.Message) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fits nats.Broker, right? why not use embedded interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it doesn't fit broker.Nats interface

cmd/http/main.go Outdated Show resolved Hide resolved
cmd/http/main.go Outdated
@@ -87,10 +80,16 @@ func main() {
thingsTracer, thingsCloser := initJaeger("things", cfg.jaegerURL, logger)
defer thingsCloser.Close()

pubsub, err := broker.New(cfg.natsURL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to say nats.New(cfg.natsURL) you are making new nats conn from nats package (e.g isolated impl of nats broker) or tomorrow kafka.New(cfg.kafka) from broker/kafka package. Just an idea
Also I would prefer messenger or msg or whatever that sounds better then pubsub.Publish() for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree for pubsub, I was never convinced. I simply replaced it by b, err := broker.New(cfg.natsURL).
I also propose that we think about to use an interface for all brokers or different ones per broker.
In my last commit I replaced broker/nats/pubsub.go by broker/nats.go. There is no nats package anymore. Eventually I could replace broker.New by broker.NewNats

go.mod Outdated Show resolved Hide resolved

// Transformer specifies API form Message transformer.
type Transformer interface {
// Transform Mainflux message to any other format.
Transform(mainflux.Message) (interface{}, error)
Transform(broker.Message) (interface{}, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better than mainflux.Message IMHO

broker/broker.go Outdated
// Nats specifies a NATS message API.
type Nats interface {
// Publish publishes message to the msessage broker.
Publish(context.Context, string, Message) error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pls put named params, it's easier to understand what are params. Now I see string string and dunno what it means.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what we should do for all the interfaces, starting from here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against but in most of our services we are not doing this. Let me open an issue to fix it everywhere

broker/broker.go Outdated
const SubjectAllChannels = "channel.>"

// Nats specifies a NATS message API.
type Nats interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You think its better to have a separate interface for each broker that we use like nats kafka etc...? Not one Interface lets say Messenger that needs to be satisfied by broker imply for example nats.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

Copy link
Contributor Author

@manuio manuio Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first idea was to have a single interface. But it's not possible unless you create a new service for this because NATS interface will never match with Kafka one (it's doable for publish but not for subscribe). For now if we want to use this as package it's better to have different interfaces .

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
broker/broker.go Outdated
// Nats specifies a NATS message API.
type Nats interface {
// Publish publishes message to the msessage broker.
Publish(context.Context, string, Message) error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what we should do for all the interfaces, starting from here.

broker/broker.go Outdated
const SubjectAllChannels = "channel.>"

// Nats specifies a NATS message API.
type Nats interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

@@ -1,14 +1,15 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: message.proto

package mainflux
package broker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change this manually, but rather fix Makefile and use it to generate this code. I don't mind keeping broker.go and messages.{proto, pb.go} in the project root.

broker/nats/pubsub.go Outdated Show resolved Hide resolved
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
twins/service.go Outdated Show resolved Hide resolved
twins/api/http/endpoint_test.go Outdated Show resolved Hide resolved
manuio and others added 9 commits March 31, 2020 17:34
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
blokovi
blokovi previously approved these changes Apr 1, 2020
broker/nats.go Show resolved Hide resolved
broker/nats.go Outdated
ps := fmt.Sprintf("%s.%s", prefix, subject)
sub, err := b.conn.Subscribe(ps, f)
if err != nil {
return nil, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not wrapping errors? Not sure if it's supposed to be wrapped everywhere or just in some places?

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

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@drasko drasko merged commit fff492b into absmach:master Apr 1, 2020
manuio added a commit that referenced this pull request Oct 12, 2020
* NOISSUEE - Create broker package for NATS

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

* Create funcs to return NATS connection

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

* mv os.exit to main

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

* Fix Reviews

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

* Fix tests and typos

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

* Fix CI

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

* Fix reviews

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

* Unify Publisher and Subscriber interfaces

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

* Rename Nats interface

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

* typo

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

* Mv message.pb.go, messsage.proto and topics.go to broker directory

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

* Fix go.mod

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

* Use mainflux broker for writers and twins services

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

* Fix go.mod

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

* Fix twins tests

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

* Fix make proto

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

* Fix message.proto

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

* Fix golangcibot

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

* regenerate message.pb.go

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

* Fix comment

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

* Fix comment

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

* Fix make proto

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

* Add NATS errors

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@manuio manuio deleted the broker branch February 23, 2022 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants