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

fix(cli):fix topic-alias-maximum error in cli connect #1444

Merged
merged 2 commits into from Sep 28, 2023

Conversation

ni00
Copy link
Contributor

@ni00 ni00 commented Sep 28, 2023

PR Checklist

If you have any questions, you can refer to the Contributing Guide

What is the current behavior?

  1. When using --topic-alias-maximum during sub and connect, it will cause an error when receiving messages.
    It's normal to use --topic-alias-maximum when pub.
  2. set a topic alias, and send multiple messages with the --multiline option, each message will contain both the topic and the topic alias.

Issue Number

#1398

What is the new behavior?

  1. fix topic-alias-maximum bug
  2. only send once topic when multiline send and topic-alias is exist

Does this PR introduce a breaking change?

  • Yes
  • No

Specific Instructions

Are there any specific instructions or things that should be known prior to review?

Other information

@ni00 ni00 changed the title Bug fixs fix(cli):fix topic-alias-maximum error in cli connect Sep 28, 2023
@ni00 ni00 self-assigned this Sep 28, 2023
@ni00 ni00 added bug Something isn't working fix Fix bug or issues CLI MQTTX CLI labels Sep 28, 2023
@ni00 ni00 added this to the v1.9.7 milestone Sep 28, 2023
@ni00 ni00 linked an issue Sep 28, 2023 that may be closed by this pull request
Comment on lines +98 to +104
let count = 0
sender._write = (line, _enc, cb) => {
const { topic, opts, protobufPath, protobufMessageName, format } = pubOpts
count++
let omitTopic = opts.properties?.topicAlias && count >= 2
const publishMessage = processPublishMessage(line.trim(), protobufPath, protobufMessageName, format)
client.publish(topic, publishMessage, opts, cb)
client.publish(omitTopic ? '' : topic, publishMessage, opts, cb)
Copy link
Member

@ysfscream ysfscream Sep 28, 2023

Choose a reason for hiding this comment

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

What is this for? If a topic alias is set after a line break, do we no longer need to enter or use the original publish topic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only need to send the topic and topic alias together for the first time. The second time, we can directly use the topic alias to send, and the topic is set to "". The current multi-line send will carry the topic and topic alias each time, which does not comply with the mqtt protocol specification.

@Red-Asuka Red-Asuka merged commit 8e35b87 into emqx:main Sep 28, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLI MQTTX CLI fix Fix bug or issues
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug] An error occurs when a received message contains a topic alias
3 participants