-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improving idea of Topic Alias #1300
Comments
redboltz
added a commit
to redboltz/MQTT.js
that referenced
this issue
Jul 12, 2021
Add automatic topic alias management functionality. - On PUBLISH sending, the client can automatic using/assin Topic Alias (optional). - On PUBLISH receiving, the topic parameter of on message handler is automatically complemented but the packet.topic preserves the original topic. Fix invalid tests.
redboltz
added a commit
to redboltz/MQTT.js
that referenced
this issue
Jul 15, 2021
Add automatic topic alias management functionality. - On PUBLISH sending, the client can automatic using/assin Topic Alias (optional). - On PUBLISH receiving, the topic parameter of on message handler is automatically complemented but the packet.topic preserves the original topic. Fix invalid tests.
This is really good @redboltz, sorry I haven't seen this earlier. Going to incorporate this into the vNext work I'm doing. |
also, did you create a pr associated with this change already? |
YoDaMa
pushed a commit
that referenced
this issue
Oct 4, 2021
* Refined Topic Alias support. (Implement #1300) Add automatic topic alias management functionality. - On PUBLISH sending, the client can automatic using/assin Topic Alias (optional). - On PUBLISH receiving, the topic parameter of on message handler is automatically complemented but the packet.topic preserves the original topic. Fix invalid tests. * Fix typo. * Fix comment. * Rename the function name from `removeTopicAlias` to `removeTopicAliasAndRecoverTopicName`. Add comments for caller side of `removeTopicAliasAndRecoverTopicName`. * Captalize label.
This has been merged in. Closing. |
This was referenced Feb 21, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overview
I found some issue about TopicAlias. It is pretty complecated so I post detailed report here.
I will create a pull request to fix the issue and some of improvements for Topic Alias.
Two independent topic alias maximum
There are two independent TopicAliasMaximum. One is client to broker, the other is broker to client.
client to broker
It is notified by CONNACK packet.
See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901088
This limits how many topic aliases can be used by the client. The value is decided by the broker.
broker to client
It is notified by CONNECT packet.
See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901051
This limits how many topic aliases to the client can be used by the broker. The value is decided by the client.
So MQTT.js client option topicAliasMaximum should be this one.
Important note
The two Topic Alias Maximum is not negotiated. They are independent values.
TopicAlias mapping is also independent.
So client to broker
topic1
-TopicAlias:1
and broker to clienttopic2
-TopicAlias:1
can exist at the same time.Topic Alias lifetime
The spec said as follows:
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113
So the lifetime of mapping is only in the network connection not session.
See https://markmail.org/message/3j47bqjdvcaxdcji
Impact for implementation
Consider the following scenario.
The PUBLISH packet in the step4 is stored in the client's outgoingStore.
It is protocol error.
The spec is a little ambiguous. It only referred to "A receiver MUST NOT carry forward", but sender and receiver is a pair. So the sender must not send topic alias just after reconnection. Consider TopicAliasMaximum at the step7 is different from the step2 case.
I guess that #1213 is caused by this problem.
Here is the solution.
Add the TopicAlias map to the sender (in this case the client).
At the step3, register the topic-alias pair to the map.
At the step4, get the topic from the alias using the map and create the packet clone for storing.
The storing packet has the recovered topic, and remove TopicAlias from the storing packet.
Then send the original packet.
At the step8, resending packet is the stored packet. So it has topic and doesn't have TopicAlias. No protocol error.
The current MQTT.js haven't implemented the topic recover storing.
In addition, the following TopicAliasMaximum handling is not enough.
MQTT.js/lib/client.js
Lines 527 to 540 in d8be59e
And corresponding test:
MQTT.js/test/client_mqtt5.js
Lines 18 to 41 in d8be59e
The test case
should allow any topicAlias when no topicAliasMaximum provided in settings
is not valid.See https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901088
Server(broker) to client is the same rule.
Convenient new feature
Now, the client need to manage TopicAlias sending map. It is to recover topic for storing. The map can be used for automatic topic alias applying and automatic topic alias allocation.
Automatic Topic Alias using
If the client sets the option
autoUseTopicAlias:true
then MQTT.js uses existing topic alias automatically.example scenario:
User doesn't need to manage which topic is mapped to which topic alias.
If the user want to register topic alias, then publish topic with topic alias.
If the user want to use topic alias, then publish topic without topic alias. If there is a mapped topic alias then added it as a property and update the topic to empty string.
Automatic Topic Alias assign
If the client sets the option
autoAssignTopicAlias:true
then MQTT.js uses existing topic alias automatically.If no topic alias exists, then assign a new vacant topic alias automatically. If topic alias is fully used, then LRU(Least Recently Used) topic-alias entry is overwritten.
example scenario:
Also user can manually register topic-alias pair using PUBLISH topic:'some', ta:X. It works well with automatic topic alias allocation
The text was updated successfully, but these errors were encountered: