MQTT considerations for large-scale public subscription deployments

When you develop MQTT subscriber applications for large-scale public deployments, there are some important factors to consider. The use of the same client ID by different clients can result in the unexpected closure of connections. You can prevent such connection disruptions by developing applications that ensure that client IDs are unique. You can then use connection policies to ensure that only these unique client IDs are allowed to connect. In large-scale subscription environments, it is also important to ensure that connections and their associated resources are used only for as long as they are needed.

Preventing session takeover for MQTT 5.0 and MQTT 3.1.1 subscriber applications

If you are using an MQTT 5.0 or MQTT 3.1.1 client, you can prevent MQTT session takeover, as follows:
  1. Develop client applications that specify zero-length client IDs. The MQTT 5.0 and MQTT 3.1.1 specifications permit the use of zero-length client IDs for clients that connect specifying cleanSession=True. When you use a zero-length client ID to connect, Eclipse Amlen generates a unique client ID and enforces the requirement for a clean session.
  2. Create connection policies that have a ClientID filter of _*.
    Note: Client IDs that are automatically generated start with an underscore.
  3. Configure endpoints with connection policies that allow client IDs that are automatically generated.

Preventing session takeover for MQTT 5.0, MQTT 3.1 and MQTT 3.0 subscriber applications

If you are using an MQTT 5.0, MQTT 3.1 or MQTT 3.0 client, you can prevent MQTT session takeover, as follows:
  1. Develop client applications that generate unique client IDs; the client IDs that are generated comprise a leading fixed string of characters and a randomly generated string of characters.

    You can use the fixed string in the client ID to configure the connection policies that authorize connection. The randomly generated string of characters prevents unintended disruption of connections that would occur if different clients generate the same client IDs for their connections.

  2. Create connection policies that have a ClientID filter that starts with the fixed string generated by your client application.
    For example, if the fixed string in your client ID is My_public_app, ensure that you set the ClientID filter to My_public_app*.
    Note: In MQTT 5.0, 3.1 and 3.0, client ID length must not exceed 23 characters.
  3. Configure endpoints with connection policies that authorize only those client IDs that start with the fixed segment of the client IDs that your client application generates.

Ensuring efficient use of connection resources

To ensure that connections are used for only as long as they are needed, you can set the AllowDurable parameter in the connection policy to False; only MQTT clients with a cleanSession=True setting can connect.