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

MF-1864 - CLI: Could not able to read messages from reader #1865

Merged
merged 3 commits into from
Jul 28, 2023

Conversation

arvindh123
Copy link
Contributor

Pull request title should be MF-XXX - description or NOISSUE - description where XXX is ID of issue that this PR relate to.
Please review the CONTRIBUTING.md file for detailed contributing guidelines.

What does this do?

  • Fixes CLI could not able to read messages from reader
  • Fixes CLI send messages topic path

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

Resolves #1864

List any changes that modify/break current functionality

NA

Have you included tests for your changes?

Yes

Did you document any new/modified functionality?

NA

Notes

@arvindh123 arvindh123 requested a review from a team as a code owner July 21, 2023 08:10
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #1865 (6c11118) into master (7cccba9) will decrease coverage by 0.02%.
Report is 1 commits behind head on master.
The diff coverage is 9.09%.

@@            Coverage Diff             @@
##           master    #1865      +/-   ##
==========================================
- Coverage   67.36%   67.34%   -0.02%     
==========================================
  Files         119      119              
  Lines        9409     9411       +2     
==========================================
  Hits         6338     6338              
- Misses       2400     2402       +2     
  Partials      671      671              
Files Changed Coverage Δ
pkg/errors/sdk_errors.go 0.00% <0.00%> (ø)
pkg/sdk/go/message.go 42.85% <50.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -22,7 +22,7 @@ func (sdk mfSDK) SendMessage(chanName, msg, key string) errors.SDKError {
subtopicPart = fmt.Sprintf("/%s", strings.Replace(chanNameParts[1], ".", "/", -1))
}

url := fmt.Sprintf("%s/channels/%s/messages/%s", sdk.httpAdapterURL, chanID, subtopicPart)
url := fmt.Sprintf("%s/channels/%s/messages%s", sdk.httpAdapterURL, chanID, subtopicPart)
Copy link
Contributor Author

@arvindh123 arvindh123 Jul 21, 2023

Choose a reason for hiding this comment

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

In Line#22 leading / is added to subtopic ,So removed here

Why removing here and not in Line#22 ?

If there is no subtopic , then ending / is no needed here, So better to have leading / in subtopics and not in main topic

@arvindh123 arvindh123 changed the title MF-1864 - CLI Could not able to read messages from reader MF-1864 - CLI: Could not able to read messages from reader Jul 21, 2023
@@ -34,7 +34,7 @@ func (sdk mfSDK) ReadMessages(chanName, token string) (MessagesPage, errors.SDKE
chanID := chanNameParts[0]
subtopicPart := ""
if len(chanNameParts) == channelParts {
subtopicPart = fmt.Sprintf("?subtopic=%s", strings.Replace(chanNameParts[1], ".", "/", -1))
subtopicPart = fmt.Sprintf("?subtopic=%s", chanNameParts[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we remove this replacement, which I think comes from differences in NATS and in MQTT how they split the topics?

Copy link
Contributor Author

@arvindh123 arvindh123 Jul 24, 2023

Choose a reason for hiding this comment

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

@drasko,

/ seperater in published topics of MQTT are replaced with . and published into NATS

According to Mainflux CLI help,
To read messages usage: read <channel_id.subtopic> <user_token>

mainflux-cli message read command calls SDK.ReadMessages function to get data from Readers.

I have published a message via mqtt with Topics channels/bb01ec9e-9c2c-429c-b0c6-de329da5c20e/messages/test/subtopic1/subtopic2,
In readers SubTopic are stored with like test.subtopic1.subtopic2

And CLI send message also have same . spereator to publish messages
mainflux-cli message send usage: send <channel_id.subtopic> <JSON_string> <thing_key>
I have published a message via mainflux-cli message send command with this topic bb01ec9e-9c2c-429c-b0c6-de329da5c20e.test.subtopic1.subtopic2,
Messages are sucessfully published and written to database

So, I decied, here replacement of . with / is not required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test by being subscribed also at MQTT topic at the same time? Do you receive messages in the RT on MQTT subscriber, and not only on Writer (which is NATS subscriber)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @drasko ,Tested,
Subscribed to MQTT topics and after subscribe receives successfully, then reads from reader

Copy link
Contributor

Choose a reason for hiding this comment

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

@arvindh123 this does not look good to me, because url below will have mix of / (in the main topic) and . in (subtopic)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@drasko , At present in CLI we can't able to read messages ,

A MQTT message is published
mosquitto_pub -u b639aacc-023d-4837-b3bd-f2016b2d93c5 -P 6a6f92e8-0997-4069-ba99-01b0d7d1427d -t "channels/ace3e631-8d9a-4825-bf0b-1a270297e76e/messages/test/subtopic1/subtopic2" -m <messageconent>

These message pickup by writer and stored them in DB as shown below

id channel subtopic publisher protocol name unit value string_value bool_value data_value sum time update_time
9391e57c-c0c7-492d-b64d-31d7e76e96e8 ace3e631-8d9a-4825-bf0b-1a270297e76e test.subtopic1.subtopic2 6a6f92e8-0997-4069-ba99-01b0d7d1427d http urn:dev:demo:10001BCD:temperature C 28.4 1690527291.310878 0.0
539ac63b-bd1c-4c2e-ba12-bad7cdf91b14 ace3e631-8d9a-4825-bf0b-1a270297e76e test.subtopic1.subtopic2 6a6f92e8-0997-4069-ba99-01b0d7d1427d http urn:dev:demo:10001BCD:humidity V 68.4 1690527291.310878 0.0

if you see in the above table
Subtopics are store in readerlike this test.subtopic1.subtopic2, which is different from topic sent from mqtt, in mqtt topics are sent with separate /

To read these message from reader , We need http api with subtopic filter like this http://localhost/reader?subtopic=test.subtopic1.subtopic2

And In CLI , we need to send command like this mainflux-cli messages read ace3e631-8d9a-4825-bf0b-1a270297e76e.test.subtopic1.subtopic2 `

Since in present code . got replace by / in readers SDK
The request sent to reader is like this http://localhost/reader?subtopic=test/subtopic1/subtopic2
Because of this request we are not getting any response.

@arvindh123 arvindh123 force-pushed the MF-1864 branch 2 times, most recently from d9dfa2d to ed23945 Compare July 26, 2023 15:20
@arvindh123 arvindh123 requested a review from drasko July 27, 2023 08:47
@@ -34,7 +34,7 @@ func (sdk mfSDK) ReadMessages(chanName, token string) (MessagesPage, errors.SDKE
chanID := chanNameParts[0]
subtopicPart := ""
if len(chanNameParts) == channelParts {
subtopicPart = fmt.Sprintf("?subtopic=%s", strings.Replace(chanNameParts[1], ".", "/", -1))
subtopicPart = fmt.Sprintf("?subtopic=%s", chanNameParts[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

@arvindh123 this does not look good to me, because url below will have mix of / (in the main topic) and . in (subtopic)

Signed-off-by: Arvindh <arvindh91@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 57d47fe into absmach:master Jul 28, 2023
1 of 3 checks passed
WashingtonKK pushed a commit to WashingtonKK/magistrala that referenced this pull request Jul 28, 2023
Signed-off-by: Arvindh <arvindh91@gmail.com>
Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
WashingtonKK pushed a commit to WashingtonKK/magistrala that referenced this pull request Jul 28, 2023
Signed-off-by: Arvindh <arvindh91@gmail.com>
Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
@dborovcanin dborovcanin deleted the MF-1864 branch August 1, 2023 21:04
rodneyosodo pushed a commit to rodneyosodo/magistrala that referenced this pull request Aug 3, 2023
Signed-off-by: Arvindh <arvindh91@gmail.com>
Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
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.

CLI Could not able to read messages from reader
4 participants