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: add subtopic support for nats messages #565

Closed
wants to merge 5 commits into from

Conversation

beres
Copy link
Contributor

@beres beres commented Jan 30, 2019

What does this do?

Nats listener subscribe to "channels.>" to catch all messages to manage also subtopic.

Which issue(s) does this PR fix/relate to?

List any changes that modify/break current functionality

Have you included tests for your changes?

Did you document any new/modified functionality?

Notes

@codecov-io
Copy link

codecov-io commented Jan 30, 2019

Codecov Report

Merging #565 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
- Coverage   87.13%   87.11%   -0.03%     
==========================================
  Files          62       62              
  Lines        3437     3391      -46     
==========================================
- Hits         2995     2954      -41     
+ Misses        300      298       -2     
+ Partials      142      139       -3
Impacted Files Coverage Δ
bootstrap/postgres/configs.go 75.77% <0%> (-2.97%) ⬇️

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 94574e3...1b7a0f1. Read the comment docs.

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.

Looks good and very nice fix, I just need to re-check this regexp in little more detail.

@nmarcetic please review

mqtt/mqtt.js Outdated Show resolved Hide resolved
manuio
manuio previously approved these changes Feb 1, 2019
Copy link
Contributor

@manuio manuio left a comment

Choose a reason for hiding this comment

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

@beres LGTM. Just update the branch please

manuio
manuio previously approved these changes Feb 8, 2019
@nmarcetic
Copy link
Collaborator

@beres Can you please update branch?

Copy link
Collaborator

@nmarcetic nmarcetic left a comment

Choose a reason for hiding this comment

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

@beres Maybe is a better idea if you can align it with authorizePublish maybe even move this parse logic to separate helper function and just use it in both publish and subscribe, its exactly the same. I don't like the idea to repeat the code and do the same thing in 2 different ways, maybe I am wrong but looks like the same logic no? What do you think?

mqtt/mqtt.js Outdated Show resolved Hide resolved
mqtt/mqtt.js Outdated Show resolved Hide resolved
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

mqtt/mqtt.js Outdated Show resolved Hide resolved
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
Copy link
Contributor

drasko commented Feb 12, 2019

@beres this looks good, please update the branch.

if (m && m.protocol !== 'mqtt') {
// rexexp has two element, the first one is the channelId, wile
// the second is undefined or the subtopic parts starting from the dot
channelParts = /^([\w\-]+)(\..+[^\.]$)*$/.exec(m.channel)
Copy link
Contributor

@anovakovic01 anovakovic01 Feb 12, 2019

Choose a reason for hiding this comment

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

@drasko AFAIK earlier we used channel only for channel ID. This means that we'll store whole topic in channel field, which is not only channel ID. Just want you to be aware of this. Also, it won't work with the current system (I think).

Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, didn't realized that there was a dot there. But still, I didn't know that you've already decided that you're going to pass subtopic here too. Maybe the rest of the team should be in sync with this change too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, subtopics will be enabled for all 4 adapters. @nmarcetic - remainder to open the issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's OK, but there is no spec how will this be done, that's why I don't know if this is how we are going to do it. So we are going to pass <channel_id>.subtopic in channel field? Why not adding separate field that will be called subtopic, and leave channel field as is? Then there will be no need to extract channel_id from string.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that would make code probably cleaner. But to see exactly what you propose, can you write here a small snippet example please.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, instead of using current channel field from here, I would add a new field: subtopic. So our structure would look like this:

message RawMessage {
	string channel     = 1;
        string subtopic = 2;
	string publisher   = 3;
	string protocol    = 4;
	string contentType = 5;
	bytes  payload     = 6;
}

In channel, we would store just channel ID, like we've done so far, and in subtopic we would store everything else (subtopic).

mqtt/mqtt.js Show resolved Hide resolved
publish(4); // Bad username or password
return;
}
var channelId = channel[1],

var channelId = channelParts[1],
Copy link
Contributor

Choose a reason for hiding this comment

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

What if channelParts has length 1.

mqtt/mqtt.js Show resolved Hide resolved
if (m && m.protocol !== 'mqtt') {
// rexexp has two element, the first one is the channelId, wile
// the second is undefined or the subtopic parts starting from the dot
channelParts = /^([\w\-]+)(\..+[^\.]$)*$/.exec(m.channel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't it?

mqtt/mqtt.js Show resolved Hide resolved
@beres
Copy link
Contributor Author

beres commented Feb 13, 2019

What do you think to reduce the valid characters in the subtopic to [a-zA-Z0-9_] and - like in channelId?
For example if the secondary argument of mqtt contains points we would have conflicts with nats

But if we limit the characters as in the case of the channelId we should do two regexp one for publish and one for subscribe, this should also accept the asterisk character.

PS: at the moment the regexp does not accept * in the subtopic

@nmarcetic
Copy link
Collaborator

Duplicated #642

@nmarcetic nmarcetic closed this Mar 12, 2019
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.

7 participants