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

feat(client): allow client id empty #1766

Merged
merged 1 commit into from
Sep 24, 2024
Merged

feat(client): allow client id empty #1766

merged 1 commit into from
Sep 24, 2024

Conversation

ysfscream
Copy link
Member

PR Checklist

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

What is the current behavior?

It is impossible to simulate MQTT 5 when the Client ID is empty. In this case, the MQTT Broker can automatically allocate a Client ID.

https://www.emqx.com/zh/blog/mqtt5-connect-properties

Issue Number

Example: https://askemq.com/t/topic/7181

What is the new behavior?

Support clearing the client ID, and do not limit the client ID to a required field.

image

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

@ysfscream ysfscream added enhancement New feature or request web MQTTX Web desktop MQTTX Desktop labels Sep 24, 2024
@ysfscream ysfscream added this to the v1.11.0 milestone Sep 24, 2024
@ysfscream ysfscream self-assigned this Sep 24, 2024
@ysfscream ysfscream changed the title feat(client): allow client empty feat(client): allow client id empty Sep 24, 2024
@Red-Asuka
Copy link
Member

@ysfscream The requirements for Client ID vary across different versions of MQTT. It might be better to dynamically validate and provide guidance on Client ID usage based on the selected MQTT version.

In MQTT, the handling of the Client ID differs across versions:

MQTT 3.1 and 3.1.1:

Clients are required to provide a Client ID, which is a unique identifier.
In MQTT 3.1, if no Client ID is provided, the connection will be rejected by the broker.
In MQTT 3.1.1, clients are allowed to send an empty Client ID, but only if the "Clean Session" (or "Clean Start") flag is set. If not, the connection will be rejected. When using an empty Client ID with Clean Session, the broker will generate a temporary Client ID for the session, but the connection state won't be persisted.
MQTT 5.0:

MQTT 5.0 introduces more flexibility regarding Client ID management. Clients can send an empty Client ID, and in this case, the broker will automatically generate a Client ID for the client.
This enhancement simplifies the connection management for clients that don't need to manually specify an ID.
In summary:

In MQTT 3.1 and 3.1.1, a Client ID is generally required (with 3.1.1 allowing it to be empty under specific conditions).
In MQTT 5.0, clients can omit the Client ID, and the broker will automatically assign one.

@ysfscream
Copy link
Member Author

ysfscream commented Sep 24, 2024

@Red-Asuka I have considered this, but for EMQX, all MQTT Versions are supported. After testing, I found that if the MQTT Broker is not supported, or when the Clean Session is False, the Client ID required error message is also very clear, so I don't want to put too many restrictions on the Client ID being empty, because the default is the value of the Client ID, and only special needs will clear the client ID.

Thanks for your reminder.

@ysfscream ysfscream merged commit 968c249 into main Sep 24, 2024
4 checks passed
@ysfscream ysfscream deleted the ysf/desktop branch September 24, 2024 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop MQTTX Desktop enhancement New feature or request web MQTTX Web
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants