Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the MQTT 5.0subscription identifiers and subscription options

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "what are MQTT 5.0subscription identifiers and subscription options". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Subscription identifier

The client can specify a subscription identifier at the time of subscription, and the server will establish and store the mapping between the subscription and the subscription identifier when the subscription is successfully created or modified. When a PUBLISH message matching the subscription is to be forwarded to the client, the server will return the subscription identifier associated with the subscription to the client along with the PUBLISH message.

Therefore, the client can establish a mapping between the subscription identifier and the message handler to direct the message to the corresponding message handler directly through the subscription identifier when the PUBLISH message is received, which is much faster than finding the message handler through topic matching.

Because SUBSCRIBE messages support multiple subscriptions, it is possible that multiple subscriptions are associated with the same subscription identifier. This can happen even with separate subscriptions, but this is allowed, but users should be aware of the possible consequences of such use. Depending on the actual subscription of the client, the final PUBLISH message received by the client may contain multiple subscription identifiers, which may be completely different or some may be the same. Here are several common situations:

The client subscribes to topic an and specifies that the subscription identifier is 1, and that the subscription identifier is 2. Because different subscription identifiers are used, messages with topics an and b can be directed to different message handlers.

The client subscribes to topic an and specifies that the subscription identifier is 1, subscribe to topic b, and specify a subscription identifier of 1. Because the same subscription identifier is used, messages with topics an and b will be directed to the same message handler.

The client subscribes to the topic aplink + and specifies that the subscription identifier is 1, and that the subscription identifier is 1 and that the subscription identifier is 1. The PUBLISH message with the subject a _ b will carry two identical subscription identifiers, and the corresponding message handler will be triggered twice.

The client subscribes to the topic aplink + and specifies that the subscription identifier is 1, and that the subscription identifier is 2. The PUBLISH message with the subject a _ b will carry two different subscription identifiers, and one message will trigger two different message handlers.

This situation of carrying multiple subscription identifiers in PUBLISH messages is usually not a problem when the message rate is low, but it may cause some performance problems when the message rate is high, so we recommend that you try your best to make sure that this happens intentionally.

Subscription options

In MQTT v5, you can use more subscription options to change the server's behavior.

QoS

See MQTT message service quality level.

No Local

In MQTT v3.1.1, if you subscribe to the topic for which you post your own messages, you will receive all your own posts.

In MQTT v5, if you set this option to 1 when you subscribe, the server will not forward your own published messages to you.

Retain As Publish

This option is used to specify whether the RETAIN identity is retained when the server forwards the message to the client, and note that this option does not affect the RETAIN identity in the retained message. So when the Retain As Publish option is set to 0, the client directly relies on the RETAIN identity in the message to distinguish whether it is a normal forwarded message or a reserved message, rather than to determine whether the message is the first message received after its subscription (the forwarded message may even be sent before the reserved message, depending on the implementation of different Broker).

Retain Handling

This option is used to specify whether the server sends a reserved message to the client when the subscription is established:

Retain Handling equals 0, and the server sends a reserved message as long as the client subscribes successfully.

Retain Handling is equal to 1, and the server sends a reserved message only if the client subscribes successfully and the subscription does not exist before. After all, there are times when the client re-initiates the subscription just to change the QoS, but it doesn't mean it wants to receive the reserved message again.

Retain Handling equals 2, and even if the customer subscribes successfully, the server will not send a reservation message.

That's all for "what are the subscription identifiers and subscription options for MQTT 5.0". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report