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

Confusing why append '/' to the end of topic name? #19

Closed
ferrirW opened this issue Mar 11, 2022 · 5 comments · Fixed by #25
Closed

Confusing why append '/' to the end of topic name? #19

ferrirW opened this issue Mar 11, 2022 · 5 comments · Fixed by #25
Labels
question Further information is requested

Comments

@ferrirW
Copy link
Contributor

ferrirW commented Mar 11, 2022

Have not find related explain, please give some description.

/**
* t1/t2/t3/
*
* @param topic
* @return
*/
public static String normalizeTopic(String topic) {
if (topic == null) {
return null;
}
if (!topic.contains(Constants.MQTT_TOPIC_DELIMITER)) {
return topic;
}
if (!topic.endsWith(Constants.MQTT_TOPIC_DELIMITER)) {
return topic + Constants.MQTT_TOPIC_DELIMITER;
}
return topic;
}

@ShannonDing ShannonDing added the question Further information is requested label Mar 11, 2022
@tianliuliu
Copy link
Contributor

ping @pingww

@pingww
Copy link
Contributor

pingww commented Mar 11, 2022

The main reason is to format it into a fixed format. As for the addition of a /, the reason is that there is a matching path in the trie, which can indeed be optimized.

@ferrirW
Copy link
Contributor Author

ferrirW commented Mar 11, 2022

ok, thanks for answering.

And found some code can be optimized:

  1. ADDFLAG & JINFLAG should be replaced with PLUS_SIGN & NUMBER_SIGN refer to unicode

  2. Some redundant containsKey before putIfAbsent()

  3. buildIntanceName -> buildInstanceName

  4. TopicUtils.isMatch("t/t1/t2/", "t/#/t2/") should be false but return true now.(I know some client will do this check like poho, however, it is better for the server to do a validation as well)

ferrirW pushed a commit to ferrirW/rocketmq-mqtt that referenced this issue Mar 11, 2022
@ShannonDing ShannonDing linked a pull request Mar 14, 2022 that will close this issue
@pingww
Copy link
Contributor

pingww commented Mar 15, 2022

"t/#/t2/" is not valid according to the mqtt protocol

@ferrirW
Copy link
Contributor Author

ferrirW commented Mar 15, 2022

"t/#/t2/" is not valid according to the mqtt protocol

yes, I just want to suggest server should do this check anyway, like: #25 (comment)

ShannonDing added a commit that referenced this issue Mar 15, 2022
* fix '#' check in topicFilter

link #19

* remove email & author info

* Add licence header to file.

Co-authored-by: wangfan <[email protected]>
Co-authored-by: dinglei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants