3 MQTT Control Packets

3.1 CONNECT – Connection Request

After a Network Connection is established by a Client to a Server, the first packet sent from the Client to the Server MUST be a CONNECT packet[MQTT-3.1.0-1].

 

A Client can only send the CONNECT packet once over a Network Connection. The Server MUST process a second CONNECT packet sent from a Client as a Protocol Error and close the Network Connection[MQTT-3.1.0-2]. Refer to section 4.13 for information about handling errors.

 

The Payload contains one or more encoded fields. They specify a unique Client identifier for the Client, a Will Topic, Will Payload, User Name and Password. All but the Client identifier can be omitted and their presence is determined based on flags in the Variable Header.

3.1.1 CONNECT Fixed Header

Figure 3‑1 - CONNECT packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (1)

Reserved

 

0

0

0

1

0

0

0

0

byte 2…

Remaining Length

 

Remaining Length field

This is the length of the Variable Header plus the length of the Payload. It is encoded as a Variable Byte Integer.

3.1.2 CONNECT Variable Header

The Variable Header for the CONNECT Packet contains the following fields in this order: Protocol Name, Protocol Level, Connect Flags, Keep Alive, and Properties. The rules for encoding Properties are described in section 2.2.2.

3.1.2.1 Protocol Name

Figure 3‑2 - Protocol Name bytes

 

Description

7

6

5

4

3

2

1

0

Protocol Name

byte 1

Length MSB (0)

0

0

0

0

0

0

0

0

byte 2

Length LSB (4)

0

0

0

0

0

1

0

0

byte 3

‘M’

0

1

0

0

1

1

0

1

byte 4

‘Q’

0

1

0

1

0

0

0

1

byte 5

‘T’

0

1

0

1

0

1

0

0

byte 6

‘T’

0

1

0

1

0

1

0

0

 

The Protocol Name is a UTF-8 Encoded String that represents the protocol name “MQTT”, capitalized as shown. The string, its offset and length will not be changed by future versions of the MQTT specification.

 

A Server which support multiple protocols uses the Protocol Name to determine whether the data is MQTT. The protocol name MUST be the UTF-8 String "MQTT". If the Server does not want to accept the CONNECT, and wishes to reveal that it is an MQTT Server it MAY send a CONNACK packet with Reason Code of 0x84 (Unsupported Protocol Version), and then it MUST close the Network Connection [MQTT-3.1.2-1].

 

Non-normative comment

Packet inspectors, such as firewalls, could use the Protocol Name to identify MQTT traffic.

3.1.2.2 Protocol Version

Figure 3‑3 - Protocol Version byte

 

Description

7

6

5

4

3

2

1

0

Protocol Level

byte 7

Version(5)

0

0

0

0

0

1

0

1

 

The one byte unsigned value that represents the revision level of the protocol used by the Client. The value of the Protocol Version field for version 5.0 of the protocol is 5 (0x05).

 

A Server which supports multiple versions of the MQTT protocol uses the Protocol Version to determine which version of MQTT the Client is using. If the Protocol Version is not 5 and the Server does not want to accept the CONNECT packet, the Server MAY send a CONNACK packet with Reason Code 0x84 (Unsupported Protocol Version) and then MUST close the Network Connection [MQTT-3.1.2-2].

3.1.2.3 Connect Flags

The Connect Flags byte contains several parameters specifying the behavior of the MQTT connection. It also indicates the presence or absence of fields in the Payload.

Figure 3‑4 - Connect Flag bits

Bit

7

6

5

4

3

2

1

0

 

User Name Flag

Password Flag

Will Retain

Will QoS

Will Flag

Clean Start

Reserved

byte 8

X

X

X

X

X

X

X

0

The Server MUST validate that the reserved flag in the CONNECT packet is set to 0[MQTT-3.1.2-3]. If the reserved flag is not 0 it is a Malformed Packet. Refer to section 4.13 for information about handling errors.

3.1.2.4 Clean Start

Position: bit 1 of the Connect Flags byte.

 

This bit specifies whether the Connection starts a new Session or is a continuation of an existing Session. Refer to section 4.1 for a definition of the Session State.

 

If a CONNECT packet is received with Clean Start is set to 1, the Client and Server MUST discard any existing Session and start a new Session[MQTT-3.1.2-4]. Consequently, the Session Present flag in CONNACK is always set to 0 if Clean Start is set to 1.

 

If a CONNECT packet is received with Clean Start set to 0 and there is a Session associated with the Client Identifier, the Server MUST resume communications with the Client based on state from the existing Session[MQTT-3.1.2-5]. If a CONNECT packet is received with Clean Start set to 0 and there is no Session associated with the Client Identifier, the Server MUST create a new Session [MQTT-3.1.2-6].

3.1.2.5 Will Flag

Position: bit 2 of the Connect Flags.

 

If the Will Flag is set to 1 this indicates that a Will Message MUST be stored on the Server and associated with the Session[MQTT-3.1.2-7]. The Will Message consists of the Will Properties, Will Topic, and Will Payload fields in the CONNECT Payload. The Will Message MUST be published after the Network Connection is subsequently closed and either the Will Delay Interval has elapsed or the Session ends, unless the Will Message has been deleted by the Server on receipt of a DISCONNECT packet with Reason Code 0x00 (Normal disconnection) or a new Network Connection for the ClientID is opened before the Will Delay Interval has elapsed[MQTT-3.1.2-8].

Situations in which the Will Message is published include, but are not limited to:

  • An I/O error or network failure detected by the Server.
  • The Client fails to communicate within the Keep Alive time.
  • The Client closes the Network Connection without first sending a DISCONNECT packet with a Reason Code 0x00 (Normal disconnection).
  • The Server closes the Network Connection without first receiving a DISCONNECT packet with a Reason Code 0x00 (Normal disconnection).

 

If the Will Flag is set to 1, the Will Properties, Will Topic, and Will Payload fields MUST be present in the Payload[MQTT-3.1.2-9]. The Will Message MUST be removed from the stored Session State in the Server once it has been published or the Server has received a DISCONNECT packet with a Reason Code of 0x00 (Normal disconnection) from the Client[MQTT-3.1.2-10].

 

The Server SHOULD publish Will Messages promptly after the Network Connection is closed and the Will Delay Interval has passed, or when the Session ends, whichever occurs first. In the case of a Server shutdown or failure, the Server MAY defer publication of Will Messages until a subsequent restart. If this happens, there might be a delay between the time the Server experienced failure and when the Will Message is published.

 

Refer to section 3.1.3.2 for information about the Will Delay Interval.

 

Non-normative comment

The Client can arrange for the Will Message to notify that Session Expiry has occurred by setting the Will Delay Interval to be longer than the Session Expiry Interval and sending DISCONNECT with Reason Code 0x04 (Disconnect with Will Message).

Solace Implementation Note

The Solace server supports Will Flag set to 1 and associated procedures as described above. Will messages are limited to 1,600 bytes in size. If a CONNECT packet is received with a Will Message that exceeds this limit, then the connection is rejected and a log is raised.

The Solace server will not send Will messages under the following conditions:

  • an administrative shutdown
  • an event broker HA failover or restart

3.1.2.6 Will QoS

Position: bits 4 and 3 of the Connect Flags.

These two bits specify the QoS level to be used when publishing the Will Message.

If the Will Flag is set to 0, then the Will QoS MUST be set to 0(0x00)[MQTT-3.1.2-11].

If the Will Flag is set to 1, the value of Will QoS can be 0 (0x00), 1 (0x01), or 2 (0x02)[MQTT-3.1.2-12]. A value of 3 (0x03) is a Malformed Packet. Refer to section 4.13 for information about handling errors.

3.1.2.7 Will Retain

Position: bit 5 of the Connect Flags.

 

This bit specifies if the Will Message is to be retained when it is published.

 

If the Will Flag is set to 0, then Will Retain MUST be set to 0 [MQTT-3.1.2-13].If the Will Flag is set to 1 and Will Retain is set to 0, the Server MUST publish the Will Message as a non-retained message[MQTT-3.1.2-14].If the Will Flag is set to 1 and Will Retain is set to 1, the Server MUST publish the Will Message as a retained message[MQTT-3.1.2-15].

 

3.1.2.8 User Name Flag

Position: bit 7 of the Connect Flags.

 

If the User Name Flag is set to 0, a User Name MUST NOT be present in the Payload[MQTT-3.1.2-16]. If the User Name Flag is set to 1, a User Name MUST be present in the Payload [MQTT-3.1.2-17].

3.1.2.9 Password Flag

Position: bit 6 of the Connect Flags.

 

If the Password Flag is set to 0, a Password MUST NOT be present in the Payload[MQTT-3.1.2-18]. If the Password Flag is set to 1, a Password MUST be present in the Payload[MQTT-3.1.2-19].

 

Non-normative comment

This version of the protocol allows the sending of a Password with no User Name, where MQTT v3.1.1 did not. This reflects the common use of Password for credentials other than a password.

3.1.2.10 Keep Alive

Figure 3‑5 - Keep Alive bytes

Bit

7

6

5

4

3

2

1

0

byte 9

Keep Alive MSB

byte 10

Keep Alive LSB

 

The Keep Alive is a Two Byte Integer which is a time interval measured in seconds. It is the maximum time interval that is permitted to elapse between the point at which the Client finishes transmitting one MQTT Control Packet and the point it starts sending the next. It is the responsibility of the Client to ensure that the interval between MQTT Control Packets being sent does not exceed the Keep Alive value. If Keep Alive is non-zero and in the absence of sending any other MQTT Control Packets, the Client MUST send a PINGREQ packet[MQTT-3.1.2-20].

 

If the Server returns a Server Keep Alive on the CONNACK packet, the Client MUST use that value instead of the value it sent as the Keep Alive[MQTT-3.1.2-21].

 

The Client can send PINGREQ at any time, irrespective of the Keep Alive value, and check for a corresponding PINGRESP to determine that the network and the Server are available.

 

If the Keep Alive value is non-zero and the Server does not receive an MQTT Control Packet from the Client within one and a half times the Keep Alive time period, it MUST close the Network Connection to the Client as if the network had failed[MQTT-3.1.2-22].

 

If a Client does not receive a PINGRESP packet within a reasonable amount of time after it has sent a PINGREQ, it SHOULD close the Network Connection to the Server.

 

A Keep Alive value of 0 has the effect of turning off the Keep Alive mechanism. If Keep Alive is 0 the Client is not obliged to send MQTT Control Packets on any particular schedule.

 

Non-normative comment

The Server may have other reasons to disconnect the Client, for instance because it is shutting down. Setting Keep Alive does not guarantee that the Client will remain connected.

 

Non-normative comment

The actual value of the Keep Alive is application specific; typically, this is a few minutes. The maximum value of 65,535 is 18 hours 12 minutes and 15 seconds.

3.1.2.11 CONNECT Properties

3.1.2.11.1 Property Length

The length of the Properties in the CONNECT packet Variable Header encoded as a Variable Byte Integer.

3.1.2.11.2 Session Expiry Interval

17 (0x11) Byte, Identifier of the Session Expiry Interval.

Followed by the Four Byte Integer representing the Session Expiry Interval in seconds. It is a Protocol Error to include the Session Expiry Interval more than once.

 

If the Session Expiry Interval is absent the value 0 is used. If it is set to 0, or is absent, the Session ends when the Network Connection is closed.

 

If the Session Expiry Interval is 0xFFFFFFFF (UINT_MAX), the Session does not expire.

 

The Client and Server MUST store the Session State after the Network Connection is closed if the Session Expiry Interval is greater than 0[MQTT-3.1.2-23].

 

Non-normative comment

The clock in the Client or Server may not be running for part of the time interval, for instance because the Client or Server are not running. This might cause the deletion of the state to be delayed.

 

Refer to section 4.1 for more information about Sessions. Refer to section 4.1.1 for details and limitations of stored state.

When the Session expires the Client and Server need not process the deletion of state atomically.

Non-normative comment

Setting Clean Start to 1 and a Session Expiry Interval of 0, is equivalent to setting CleanSession to 1 in the MQTT Specification Version 3.1.1. Setting Clean Start to 0 and no Session Expiry Interval, is equivalent to setting CleanSession to 0 in the MQTT Specification Version 3.1.1.

 

Non-normative comment

A Client that only wants to process messages while connected will set the Clean Start to 1 and set the Session Expiry Interval to 0. It will not receive Application Messages published before it connected and has to subscribe afresh to any topics that it is interested in each time it connects.

 

Non-normative comment

A Client might be connecting to a Server using a network that provides intermittent connectivity. This Client can use a short Session Expiry Interval so that it can reconnect when the network is available again and continue reliable message delivery. If the Client does not reconnect, allowing the Session to expire, then Application Messages will be lost.

 

Non-normative comment

When a Client connects with a long Session Expiry Interval, it is requesting that the Server maintain its MQTT session state after it disconnects for an extended period. Clients should only connect with a long Session Expiry Interval if they intend to reconnect to the Server at some later point in time. When a Client has determined that it has no further use for the Session it should disconnect with a Session Expiry Interval set to 0.

 

Non-normative comment

The Client should always use the Session Present flag in the CONNACK to determine whether the Server has a Session State for this Client.

 

Non-normative comment

The Client can avoid implementing its own Session expiry and instead rely on the Session Present flag returned from the Server to determine if the Session had expired. If the Client does implement its own Session expiry, it needs to store the time at which the Session State will be deleted as part of its Session State.

3.1.2.11.3 Receive Maximum

33 (0x21) Byte, Identifier of the Receive Maximum.

Followed by the Two Byte Integer representing the Receive Maximum value. It is a Protocol Error to include the Receive Maximum value more than once or for it to have the value 0.

 

The Client uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently. There is no mechanism to limit the QoS 0 publications that the Server might try to send.

 

The value of Receive Maximum applies only to the current Network Connection. If the Receive Maximum value is absent then its value defaults to 65,535.

 

Refer to section 4.9 Flow Control for details of how the Receive Maximum is used.

 

3.1.2.11.4 Maximum Packet Size

39 (0x27) Byte, Identifier of the Maximum Packet Size.

Followed by a Four Byte Integer representing the Maximum Packet Size the Client is willing to accept. If the Maximum Packet Size is not present, no limit on the packet size is imposed beyond the limitations in the protocol as a result of the remaining length encoding and the protocol header sizes.

 

It is a Protocol Error to include the Maximum Packet Size more than once, or for the value to be set to zero.

Non-normative comment

It is the responsibility of the application to select a suitable Maximum Packet Size value if it chooses to restrict the Maximum Packet Size.

The packet size is the total number of bytes in an MQTT Control Packet, as defined in section 2.1.4. The Client uses the Maximum Packet Size to inform the Server that it will not process packets exceeding this limit.

The Server MUST NOT send packets exceeding Maximum Packet Size to the Client [MQTT-3.1.2-24]. If a Client receives a packet whose size exceeds this limit, this is a Protocol Error, the Client uses DISCONNECT with Reason Code 0x95 (Packet too large), as described in section 4.13.

Where a Packet is too large to send, the Server MUST discard it without sending it and then behave as if it had completed sending that Application Message[MQTT-3.1.2-25].

In the case of a Shared Subscription where the message is too large to send to one or more of the Clients but other Clients can receive it, the Server can choose either discard the message without sending the message to any of the Clients, or to send the message to one of the Clients that can receive it.

 

Non-normative comment

Where a packet is discarded without being sent, the Server could place the discarded packet on a ‘dead letter queue’ or perform other diagnostic action. Such actions are outside the scope of this specification.

 

3.1.2.11.5 Topic Alias Maximum

34 (0x22) Byte, Identifier of the Topic Alias Maximum.

Followed by the Two Byte Integer representing the Topic Alias Maximum value. It is a Protocol Error to include the Topic Alias Maximum value more than once. If the Topic Alias Maximum property is absent, the default value is 0.

This value indicates the highest value that the Client will accept as a Topic Alias sent by the Server. The Client uses this value to limit the number of Topic Aliases that it is willing to hold on this Connection. The Server MUST NOT send a Topic Alias in a PUBLISH packet to the Client greater than Topic Alias Maximum[MQTT-3.1.2-26]. A value of 0 indicates that the Client does not accept any Topic Aliases on this connection. If Topic Alias Maximum is absent or zero, the Server MUST NOT send any Topic Aliases to the Client[MQTT-3.1.2-27].

Solace Implementation Note

Solace does not support Topic Alias.

3.1.2.11.6 Request Response Information

25 (0x19) Byte, Identifier of the Request Response Information.

Followed by a Byte with a value of either 0 or 1. It is Protocol Error to include the Request Response Information more than once, or to have a value other than 0 or 1. If the Request Response Information is absent, the value of 0 is used.

 

The Client uses this value to request the Server to return Response Information in the CONNACK. A value of 0 indicates that the Server MUST NOT return Response Information[MQTT-3.1.2-28]. If the value is 1 the Server MAY return Response Information in the CONNACK packet.

Solace Implementation Note

When Response Information is 1 the CONNACK always includes Response Information. Applications SHOULD use this as a prefix for building their PUBLISH Response Topics. This is the same prefix that is returned to clients that subscribe to #SYS/client/reply-to.

 

Non-normative comment

The Server can choose not to include Response Information in the CONNACK, even if the Client requested it.

 

Refer to section 4.10 for more information about Request / Response.

3.1.2.11.7 Request Problem Information

23 (0x17) Byte, Identifier of the Request Problem Information.

Followed by a Byte with a value of either 0 or 1. It is a Protocol Error to include Request Problem Information more than once, or to have a value other than 0 or 1. If the Request Problem Information is absent, the value of 1 is used.

 

The Client uses this value to indicate whether the Reason String or User Properties are sent in the case of failures.

 

If the value of Request Problem Information is 0, the Server MAY return a Reason String or User Properties on a CONNACK or DISCONNECT packet, but MUST NOT send a Reason String or User Properties on any packet other than PUBLISH, CONNACK, or DISCONNECT[MQTT-3.1.2-29]. If the value is 0 and the Client receives a Reason String or User Properties in a packet other than PUBLISH, CONNACK, or DISCONNECT, it uses a DISCONNECT packet with Reason Code 0x82 (Protocol Error) as described in section 4.13 Handling errors.

 

If this value is 1, the Server MAY return a Reason String or User Properties on any packet where it is allowed.

3.1.2.11.8 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by a UTF-8 String Pair.

 

The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

Non-normative comment

User Properties on the CONNECT packet can be used to send connection related properties from the Client to the Server. The meaning of these properties is not defined by this specification.

Solace Implementation Note

Solace does not define any User Properties for the CONNECT packet. Any provided User Property is ignored.

3.1.2.11.9 Authentication Method

21 (0x15) Byte, Identifier of the Authentication Method.

Followed by a UTF-8 Encoded String containing the name of the authentication method used for extended authentication .It is a Protocol Error to include Authentication Method more than once.

If Authentication Method is absent, extended authentication is not performed. Refer to section 4.12.

 

If a Client sets an Authentication Method in the CONNECT, the Client MUST NOT send any packets other than AUTH or DISCONNECT packets until it has received a CONNACK packet[MQTT-3.1.2-30].

Solace Implementation Note

Solace does not support extended authentication. If an Authentication Method is provided in the CONNACK the connection is closed.

3.1.2.11.10 Authentication Data

22 (0x16) Byte, Identifier of the Authentication Data.

Followed by Binary Data containing authentication data. It is a Protocol Error to include Authentication Data if there is no Authentication Method. It is a Protocol Error to include Authentication Data more than once.

 

The contents of this data are defined by the authentication method. Refer to section 4.12 for more information about extended authentication.

3.1.2.12 Variable Header non-normative example

Figure 3‑6 - Variable Header example

 

Description

7

6

5

4

3

2

1

0

Protocol Name

byte 1

Length MSB (0)

0

0

0

0

0

0

0

0

byte 2

Length LSB (4)

0

0

0

0

0

1

0

0

byte 3

‘M’

0

1

0

0

1

1

0

1

byte 4

‘Q’

0

1

0

1

0

0

0

1

byte 5

‘T’

0

1

0

1

0

1

0

0

byte 6

‘T’

0

1

0

1

0

1

0

0

Protocol Version

 

Description

7

6

5

4

3

2

1

0

byte 7

Version (5)

0

0

0

0

0

1

0

1

Connect Flags

 

 

 

 

byte 8

User Name Flag (1)

Password Flag (1)

Will Retain (0)

Will QoS (01)

Will Flag (1)

Clean Start(1)

Reserved (0)

 

 

 

 

1

 

 

 

 

1

 

 

 

 

0

 

 

 

 

0

 

 

 

 

1

 

 

 

 

1

 

 

 

 

1

 

 

 

 

0

Keep Alive

byte 9

Keep Alive MSB (0)

0

0

0

0

0

0

0

0

byte 10

Keep Alive LSB (10)

0

0

0

0

1

0

1

0

Properties

byte 11

Length (5)

0

0

0

0

0

1

0

1

byte 12

Session Expiry Interval identifier (17)

0

0

0

1

0

0

0

1

byte 13

Session Expiry Interval (10)

0

0

0

0

0

0

0

0

byte 14

0

0

0

0

0

0

0

0

byte 15

0

0

0

0

0

0

0

0

byte 16

0

0

0

0

1

0

1

0

3.1.3 CONNECT Payload

The Payload of the CONNECT packet contains one or more length-prefixed fields, whose presence is determined by the flags in the Variable Header. These fields, if present, MUST appear in the order Client Identifier, Will Properties, Will Topic, Will Payload, User Name, Password[MQTT-3.1.3-1].

3.1.3.1 Client Identifier (ClientID)

The Client Identifier (ClientID) identifies the Client to the Server. Each Client connecting to the Server has a unique ClientID. The ClientID MUST be used by Clients and by Servers to identify state that they hold relating to this MQTT Session between the Client and the Server[MQTT-3.1.3-2]. Refer to section 4.1 for more information about Session State.

 

The ClientID MUST be present and is the first field in the CONNECT packet Payload [MQTT-3.1.3-3].

 

The ClientID MUST be a UTF-8 Encoded String as defined in section 1.5.4[MQTT-3.1.3-4].

 

The Server MUST allow ClientID’s which are between 1 and 23 UTF-8 encoded bytes in length, and that contain only the characters

"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" [MQTT-3.1.3-5].

 

The Server MAY allow ClientID’s that contain more than 23 encoded bytes. The Server MAY allow ClientID’s that contain characters not included in the list given above.

 

A Server MAY allow a Client to supply a ClientID that has a length of zero bytes, however if it does so the Server MUST treat this as a special case and assign a unique ClientID to that Client[MQTT-3.1.3-6]. It MUST then process the CONNECT packet as if the Client had provided that unique ClientID, and MUST return the Assigned Client Identifier in the CONNACK packet[MQTT-3.1.3-7].

 

If the Server rejects the ClientID it MAY respond to the CONNECT packet with a CONNACK using Reason Code 0x85 (Client Identifier not valid) as described in section 4.13 Handling errors, and then it MUST close the Network Connection[MQTT-3.1.3-8].

 

Non-normative comment

A Client implementation could provide a convenience method to generate a random ClientID. Clients using this method should take care to avoid creating long-lived orphaned Sessions.

Solace Implementation Note

  • ClientIds can be up to 128 bytes in length
  • ClientIds can contain any UTF-8 characters as allowed by section 1.5.4.

3.1.3.2 Will Properties

If the Will Flag is set to 1, the Will Properties is the next field in the Payload. The Will Properties field defines the Application Message properties to be sent with the Will Message when it is published, and properties which define when to publish the Will Message. The Will Properties consists of a Property Length and the Properties.

3.1.3.2.1 Property Length

The length of the Properties in the Will Properties encoded as a Variable Byte Integer.

3.1.3.2.2 Will Delay Interval

24 (0x18) Byte, Identifier of the Will Delay Interval.

Followed by the Four Byte Integer representing the Will Delay Interval in seconds. It is a Protocol Error to include the Will Delay Interval more than once. If the Will Delay Interval is absent, the default value is 0 and there is no delay before the Will Message is published.

 

The Server delays publishing the Client’s Will Message until the Will Delay Interval has passed or the Session ends, whichever happens first. If a new Network Connection to this Session is made before the Will Delay Interval has passed, the Server MUST NOT send the Will Message[MQTT-3.1.3-9].

 

Non-normative comment

One use of this is to avoid publishing Will Messages if there is a temporary network disconnection and the Client succeeds in reconnecting and continuing its Session before the Will Message is published.

 

Non-normative comment

If a Network Connection uses a Client Identifier of an existing Network Connection to the Server, the Will Message for the exiting connection is sent unless the new connection specifies Clean Start of 0 and the Will Delay is greater than zero. If the Will Delay is 0 the Will Message is sent at the close of the existing Network Connection, and if Clean Start is 1 the Will Message is sent because the Session ends.

Solace Implementation Note

Solace does not support Will Delay. If non-zero, the connection will be closed.

3.1.3.2.3 Payload Format Indicator

1 (0x01) Byte, Identifier of the Payload Format Indicator.

Followed by the value of the Payload Format Indicator, either of:

  • 0 (0x00) Byte Indicates that the Will Message is unspecified bytes, which is equivalent to not sending a Payload Format Indicator.
  • 1 (0x01) Byte Indicates that the Will Message is UTF-8 Encoded Character Data. The UTF-8 data in the Payload MUST be well-formed UTF-8 as defined by the Unicode specification [Unicode] and restated in RFC 3629 [RFC3629].

It is a Protocol Error to include the Payload Format Indicator more than once. The Server MAY validate that the Will Message is of the format indicated, and if it is not send a CONNACK with the Reason Code of 0x99 (Payload format invalid) as described in section 4.13.

3.1.3.2.4 Message Expiry Interval

2 (0x02) Byte, Identifier of the Message Expiry Interval.

Followed by the Four Byte Integer representing the Message Expiry Interval. It is a Protocol Error to include the Message Expiry Interval more than once.

 

If present, the Four Byte value is the lifetime of the Will Message in seconds and is sent as the Publication Expiry Interval when the Server publishes the Will Message.

 

If absent, no Message Expiry Interval is sent when the Server publishes the Will Message.

3.1.3.2.5 Content Type

3 (0x03) Identifier of the Content Type.

Followed by a UTF-8 Encoded String describing the content of the Will Message. It is a Protocol Error to include the Content Type more than once. The value of the Content Type is defined by the sending and receiving application.

3.1.3.2.6 Response Topic

8 (0x08) Byte, Identifier of the Response Topic.

Followed by a UTF-8 Encoded String which is used as the Topic Name for a response message. It is a Protocol Error to include the Response Topic more than once. The presence of a Response Topic identifies the Will Message as a Request.

Refer to section 4.10 for more information about Request / Response.

3.1.3.2.7 Correlation Data

9 (0x09) Byte, Identifier of the Correlation Data.

Followed by Binary Data. The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received. It is a Protocol Error to include Correlation Data more than once. If the Correlation Data is not present, the Requester does not require any correlation data.

 

The value of the Correlation Data only has meaning to the sender of the Request Message and receiver of the Response Message.

 

Refer to section 4.10 for more information about Request / Response

3.1.3.2.8 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by a UTF-8 String Pair. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

The Server MUST maintain the order of User Properties when publishing the Will Message[MQTT-3.1.3-10].

 

Non-normative comment

This property is intended to provide a means of transferring application layer name-value tags whose meaning and interpretation are known only by the application programs responsible for sending and receiving them.

3.1.3.3 Will Topic

If the Will Flag is set to 1, the Will Topic is the next field in the Payload. The Will Topic MUST be a UTF-8 Encoded String as defined in section 1.5.4[MQTT-3.1.3-11].

Solace Implementation Note

A Will Topic must be valid as per Solace limitations described in section 4.7. Invalid topics will cause the CONNECT to be rejected or the Will message to be discarded if published.

3.1.3.4 Will Payload

If the Will Flag is set to 1 the Will Payload is the next field in the Payload. The Will Payload defines the Application Message Payload that is to be published to the Will Topic as described in section 3.1.2.5. This field consists of Binary Data.

3.1.3.5 User Name

If the User Name Flag is set to 1, the User Name is the next field in the Payload. The User Name MUST be a UTF-8 Encoded String as defined in section 1.5.4[MQTT-3.1.3-12]. It can be used by the Server for authentication and authorization.

Solace Implementation Note

If OAuth is used to authenticate the MQTT Client, then the Solace client user name used to establish connection policy is taken from an OAuth token (or introspection thereof) and the MQTT User Name in the CONNECT packet is ignored.

If an SSL Client Certificate is used by the MQTT Client to authenticate, then the Solace client user name used to establish connection policy is taken from the certificate and the MQTT User Name in the CONNECT packet is ignored. This behavior is consistent across all Solace-supported protocols. MQTT is silent about the handling of user name in the certificate versus user name in the CONNECT packet.

Otherwise

  • The Solace server maps the MQTT User Name to the Solace Client User Name for authentication purposes.
  • The Solace server supports the ability for MQTT User Names (that is,  Solace Client User Names) to be predefined on the appliance and to map directly to a client profile and Access Control List (ACL) profile for authorization purposes.
  • The Solace server supports the ability for MQTT User Names to NOT be predefined on the appliance.  In this case, the MQTT connection is associated with a client profile and ACL profile either through the default client user name (named “default”) or through an LDAP lookup of an LDAP group based on the MQTT User Name, which then maps to a client  profile and an ACL profile.
  • The maximum supported length of the MQTT User Name is 189 characters – same as the Solace client user name.  If the MQTT client provides a longer User Name, then the connection is rejected because the full user name cannot be passed to the appropriate authentication and authorization service.

3.1.3.6 Password

If the Password Flag is set to 1, the Password is the next field in the Payload. The Password field is Binary Data. Although this field is called Password, it can be used to carry any credential information.

Solace Implementation Note

The length of passwords that may be used are limited as follows:

  • MQTT clients that use LDAP servers to authenticate can use passwords that contain up to 64,000 characters, including null characters. Clients that use RADIUS authentication are limited to 128 characters.
  • The maximum supported password length for LDAP and RADIUS authentication is 128 characters. If the MQTT client provides a longer password, then the connection will be rejected because the full password cannot be passed to the appropriate authentication service. Passwords cannot contain binary data because null characters were treated as string terminators.
  • For clients that use the Solace internal database for authentication, the length of a password is limited to 128 characters.

The password field is allowed to contain OAuth v2 tokens. These tokens must be supplied in a very specific format:

OAUTH~<Provider>~access_token

The password field can also contain OpenID Connect tokens:

OPENID~<Provider>~id_token~access_token

In both cases, the password must start with a literal string "OAUTH~" or "OPENID~" and be followed by the name of the provider (which must match one of the configured providers on the broker, or it can be zero-length which indicates that Solace should use the configured default provider on the broker), and then another tilde, and then the tokens (separated by a tilde).

The access_token must be either a JWT or a URL-encoded opaque token.

3.1.4 CONNECT Actions

Note that a Server MAY support multiple protocols (including other versions of the MQTT protocol) on the same TCP port or other network endpoint. If the Server determines that the protocol is MQTT v5.0 then it validates the connection attempt as follows.

  1. If the Server does not receive a CONNECT packet within a reasonable amount of time after the Network Connection is established, the Server SHOULD close the Network Connection.
  2. The Server MUST validate that the CONNECT packet matches the format described in section 3.1 and close the Network Connection if it does not match[MQTT-3.1.4-1]. The Server MAY send a CONNACK with a Reason Code of 0x80 or greater as described in section 4.13 before closing the Network Connection.
  3. The Server MAY check that the contents of the CONNECT packet meet any further restrictions and SHOULD perform authentication and authorization checks. If any of these checks fail, it MUST close the Network Connection[MQTT-3.1.4-2]. Before closing the Network Connection, it MAY send an appropriate CONNACK response with a Reason Code of 0x80 or greater as described in section 3.2 and section 4.13.

If validation is successful, the Server performs the following steps.

  1.  If the ClientID represents a Client already connected to the Server, the Server sends a DISCONNECT packet to the existing Client with Reason Code of 0x8E (Session taken over) as described in section 4.13 and MUST close the Network Connection of the existing Client[MQTT-3.1.4-3]. If the existing Client has a Will Message, that Will Message is published as described in section 3.1.2.5.

    Solace Implementation Note

    By default, if the ClientId represents a Client already connected to the Solace PubSub+ event broker, then the existing Client connection will be disconnected. However, an administrator can use the no replace-duplicate-client-connections Authentication Config command in the Solace CLI to override this behavior to leave the existing client connected.

    Non-normative comment

    If the Will Delay Interval of the existing Network Connection is 0 and there is a Will Message, it will be sent because the Network Connection is closed. If the Session Expiry Interval of the existing Network Connection is 0, or the new Network Connection has Clean Start set to 1 then if the existing Network Connection has a Will Message it will be sent because the original Session is ended on the takeover.

  2. The Server MUST perform the processing of Clean Start that is described in section 3.1.2.4[MQTT-3.1.4-4].

  3. The Server MUST acknowledge the CONNECT packet with a CONNACK packet containing a 0x00 (Success) Reason Code[MQTT-3.1.4-5].

    Non-normative comment

    It is recommended that authentication and authorization checks be performed if the Server is being used to process any form of business critical data. If these checks succeed, the Server responds by sending CONNACK with a 0x00 (Success) Reason Code. If they fail, it is suggested that the Server does not send a CONNACK at all, as this could alert a potential attacker to the presence of the MQTT Server and encourage such an attacker to launch a denial of service or password-guessing attack.

  4. Start message delivery and Keep Alive monitoring.

Clients are allowed to send further MQTT Control Packets immediately after sending a CONNECT packet; Clients need not wait for a CONNACK packet to arrive from the Server. If the Server rejects the CONNECT, it MUST NOT process any data sent by the Client after the CONNECT packet except AUTH packets[MQTT-3.1.4-6].

 

Non-normative comment

Clients typically wait for a CONNACK packet, However, if the Client exploits its freedom to send MQTT Control Packets before it receives a CONNACK, it might simplify the Client implementation as it does not have to police the connected state. The Client accepts that any data that it sends before it receives a CONNACK packet from the Server will not be processed if the Server rejects the connection.

 

Non-normative comment

Clients that send MQTT Control Packets before they receive CONNACK will be unaware of the Server constraints and whether any existing Session is being used.

 

Non-normative comment

The Server can limit reading from the Network Connection or close the Network Connection if the Client sends too much data before authentication is complete. This is suggested as a way of avoiding denial of service attacks.

3.2 CONNACK – Connect acknowledgement

The CONNACK packet is the packet sent by the Server in response to a CONNECT packet received from a Client. The Server MUST send a CONNACK with a 0x00 (Success) Reason Code before sending any Packet other than AUTH[MQTT-3.2.0-1]. The Server MUST NOT send more than one CONNACK in a Network Connection[MQTT-3.2.0-2].

If the Client does not receive a CONNACK packet from the Server within a reasonable amount of time, the Client SHOULD close the Network Connection. A "reasonable" amount of time depends on the type of application and the communications infrastructure.

3.2.1 CONNACK Fixed Header

The Fixed Header format is illustrated in Figure 3-7.

Figure 3‑7 – CONNACK packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet Type (2)

Reserved

 

0

0

1

0

0

0

0

0

byte 2

Remaining Length

 

Remaining Length field

This is the length of the Variable Header encoded as a Variable Byte Integer.

3.2.2 CONNACK Variable Header

The Variable Header of the CONNACK Packet contains the following fields in the order: Connect Acknowledge Flags, Connect Reason Code, and Properties. The rules for encoding Properties are described in section 2.2.2.

3.2.2.1 Connect Acknowledge Flags

Byte 1 is the "Connect Acknowledge Flags". Bits 7-1 are reserved and MUST be set to 0[MQTT-3.2.2-1].

 

Bit 0 is the Session Present Flag.

 

3.2.2.1.1 Session Present

Position: bit 0 of the Connect Acknowledge Flags.

 

The Session Present flag informs the Client whether the Server is using Session State from a previous connection for this ClientID. This allows the Client and Server to have a consistent view of the Session State.

 

If the Server accepts a connection with Clean Start set to 1, the Server MUST set Session Present to 0 in the CONNACK packet in addition to setting a 0x00 (Success) Reason Code in the CONNACK packet[MQTT-3.2.2-2].

 

If the Server accepts a connection with Clean Start set to 0 and the Server has Session State for the ClientID, it MUST set Session Present to 1 in the CONNACK packet, otherwise it MUST set Session Present to 0 in the CONNACK packet. In both cases it MUST set a 0x00 (Success) Reason Code in the CONNACK packet [MQTT-3.2.2-3].

 

If the value of Session Present received by the Client from the Server is not as expected, the Client proceeds as follows:

  • If the Client does not have Session State and receives Session Present set to 1 it MUST close the Network Connection[MQTT-3.2.2-4]. If it wishes to restart with a new Session the Client can reconnect using Clean Start set to 1.
  • If the Client does have Session State and receives Session Present set to 0 it MUST discard its Session State if it continues with the Network Connection[MQTT-3.2.2-5].

 

If a Server sends a CONNACK packet containing a non-zero Reason Code it MUST set Session Present to 0 [MQTT-3.2.2-6].

3.2.2.2 Connect Reason Code

Byte 2 in the Variable Header is the Connect Reason Code.

 

The values the Connect Reason Code are shown below. If a well formed CONNECT packet is received by the Server, but the Server is unable to complete the Connection the Server MAY send a CONNACK packet containing the appropriate Connect Reason code from this table. If a Server sends a CONNACK packet containing a Reason code of 128 or greater it MUST then close the Network Connection[MQTT-3.2.2-7].

Table 3‑1 - Connect Reason Code values

Value

Hex

Reason Code name

Description

0

0x00

Success

The Connection is accepted.

128

0x80

Unspecified error

The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.

129

0x81

Malformed Packet

Data within the CONNECT packet could not be correctly parsed.

130

0x82

Protocol Error

Data in the CONNECT packet does not conform to this specification.

131

0x83

Implementation specific error

The CONNECT is valid but is not accepted by this Server.

132

0x84

Unsupported Protocol Version

The Server does not support the version of the MQTT protocol requested by the Client.

133

0x85

Client Identifier not valid

The Client Identifier is a valid string but is not allowed by the Server.

134

0x86

Bad User Name or Password

The Server does not accept the User Name or Password specified by the Client

135

0x87

Not authorized

The Client is not authorized to connect.

136

0x88

Server unavailable

The MQTT Server is not available.

137

0x89

Server busy

The Server is busy. Try again later.

138

0x8A

Banned

This Client has been banned by administrative action. Contact the server administrator.

140

0x8C

Bad authentication method

The authentication method is not supported or does not match the authentication method currently in use.

144

0x90

Topic Name invalid

The Will Topic Name is not malformed, but is not accepted by this Server.

149

0x95

Packet too large

The CONNECT packet exceeded the maximum permissible size.

151

0x97

Quota exceeded

An implementation or administrative imposed limit has been exceeded.

153

0x99

Payload format invalid

The Will Payload does not match the specified Payload Format Indicator.

154

0x9A

Retain not supported

The Server does not support retained messages, and Will Retain was set to 1.

155

0x9B

QoS not supported

The Server does not support the QoS set in Will QoS.

156

0x9C

Use another server

The Client should temporarily use another server.

157

0x9D

Server moved

The Client should permanently use another server.

159

0x9F

Connection rate exceeded

The connection rate limit has been exceeded.

 

The Server sending the CONNACK packet MUST use one of the Connect Reason Code valuesT-3.2.2-8].

 

Non-normative comment

Reason Code 0x80 (Unspecified error) may be used where the Server knows the reason for the failure but does not wish to reveal it to the Client, or when none of the other Reason Code values applies.

 

The Server may choose to close the Network Connection without sending a CONNACK to enhance security in the case where an error is found on the CONNECT. For instance, when on a public network and the connection has not been authorized it might be unwise to indicate that this is an MQTT Server.

3.2.2.3 CONNACK Properties

3.2.2.3.1 Property Length

This is the length of the Properties in the CONNACK packet Variable Header encoded as a Variable Byte Integer.

 

3.2.2.3.2 Session Expiry Interval

17 (0x11) Byte, Identifier of the Session Expiry Interval.

Followed by the Four Byte Integer representing the Session Expiry Interval in seconds. It is a Protocol Error to include the Session Expiry Interval more than once.

If the Session Expiry Interval is absent the value in the CONNECT Packet used. The server uses this property to inform the Client that it is using a value other than that sent by the Client in the CONNACK. Refer to section 3.1.2.11.2 for a description of the use of Session Expiry Interval.

 

3.2.2.3.3 Receive Maximum

33 (0x21) Byte, Identifier of the Receive Maximum.

Followed by the Two Byte Integer representing the Receive Maximum value. It is a Protocol Error to include the Receive Maximum value more than once or for it to have the value 0.

 

The Server uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently for the Client. It does not provide a mechanism to limit the QoS 0 publications that the Client might try to send.

 

If the Receive Maximum value is absent, then its value defaults to 65,535.

 

Refer to section 4.9 Flow Control for details of how the Receive Maximum is used.

3.2.2.3.4 Maximum QoS

36 (0x24) Byte, Identifier of the Maximum QoS.

Followed by a Byte with a value of either 0 or 1. It is a Protocol Error to include Maximum QoS more than once, or to have a value other than 0 or 1. If the Maximum QoS is absent, the Client uses a Maximum QoS of 2.

 

If a Server does not support QoS 1 or QoS 2 PUBLISH packets it MUST send a Maximum QoS in the CONNACK packet specifying the highest QoS it supports[MQTT-3.2.2-9]. A Server that does not support QoS 1 or QoS 2 PUBLISH packets MUST still accept SUBSCRIBE packets containing a Requested QoS of 0, 1 or 2[MQTT-3.2.2-10].

 

If a Client receives a Maximum QoS from a Server, it MUST NOT send PUBLISH packets at a QoS level exceeding the Maximum QoS level specified[MQTT-3.2.2-11]. It is a Protocol Error if the Server receives a PUBLISH packet with a QoS greater than the Maximum QoS it specified. In this case use DISCONNECT with Reason Code 0x9B (QoS not supported) as described in section 4.13 Handling errors.

 

If a Server receives a CONNECT packet containing a Will QoS that exceeds its capabilities, it MUST reject the connection. It SHOULD use a CONNACK packet with Reason Code 0x9B (QoS not supported) as described in section 4.13 Handling errors, and MUST close the Network Connection [MQTT-3.2.2-12].

 

Non-normative comment

A Client does not need to support QoS 1 or QoS 2 PUBLISH packets. If this is the case, the Client simply restricts the maximum QoS field in any SUBSCRIBE commands it sends to a value it can support.

 

Solace Implementation Note

Solace returns a Maximum QoS of 0 if the Assured Delivery feature is not enabled for the client.

 

3.2.2.3.5 Retain Available

37 (0x25) Byte, Identifier of Retain Available.

Followed by a Byte field. If present, this byte declares whether the Server supports retained messages. A value of 0 means that retained messages are not supported. A value of 1 means retained messages are supported. If not present, then retained messages are supported. It is a Protocol Error to include Retain Available more than once or to use a value other than 0 or 1.

 

If a Server receives a CONNECT packet containing a Will Message with the Will Retain set to 1, and it does not support retained messages, the Server MUST reject the connection request. It SHOULD send CONNACK with Reason Code 0x9A (Retain not supported) and then it MUST close the Network Connection[MQTT-3.2.2-13].

 

A Client receiving Retain Available set to 0 from the Server MUST NOT send a PUBLISH packet with the RETAIN flag set to 1[MQTT-3.2.2-14]. If the Server receives such a packet, this is a Protocol Error. The Server SHOULD send a DISCONNECT with Reason Code of 0x9A (Retain not supported) as described in section 4.13.

 

Solace Implementation Note

Solace returns Retain Available only if retain is enabled for the Message VPN the client is connecting to.

 

3.2.2.3.6 Maximum Packet Size

39 (0x27) Byte, Identifier of the Maximum Packet Size.

Followed by a Four Byte Integer representing the Maximum Packet Size the Server is willing to accept. If the Maximum Packet Size is not present, there is no limit on the packet size imposed beyond the limitations in the protocol as a result of the remaining length encoding and the protocol header sizes.

 

It is a Protocol Error to include the Maximum Packet Size more than once, or for the value to be set to zero.

 

The packet size is the total number of bytes in an MQTT Control Packet, as defined in section 2.1.4.The Server uses the Maximum Packet Size to inform the Client that it will not process packets whose size exceeds this limit.

 

The Client MUST NOT send packets exceeding Maximum Packet Size to the Server[MQTT-3.2.2-15]. If a Server receives a packet whose size exceeds this limit, this is a Protocol Error, the Server uses DISCONNECT with Reason Code 0x95 (Packet too large), as described in section 4.13.

 

Solace Implementation Note

Solace does not send a Maximum Packet Size in the CONNACK. However, there are limits to the size of messages.

 

3.2.2.3.7 Assigned Client Identifier

18 (0x12) Byte, Identifier of the Assigned Client Identifier.

Followed by the UTF-8 string which is the Assigned Client Identifier. It is a Protocol Error to include the Assigned Client Identifier more than once.

 

The Client Identifier which was assigned by the Server because a zero length Client Identifier was found in the CONNECT packet.

 

If the Client connects using a zero length Client Identifier, the Server MUST respond with a CONNACK containing an Assigned Client Identifier. The Assigned Client Identifier MUST be a new Client Identifier not used by any other Session currently in the Server[MQTT-3.2.2-16].

 

3.2.2.3.8 Topic Alias Maximum

34 (0x22) Byte, Identifier of the Topic Alias Maximum.

Followed by the Two Byte Integer representing the Topic Alias Maximum value. It is a Protocol Error to include the Topic Alias Maximum value more than once. If the Topic Alias Maximum property is absent, the default value is 0.

 

This value indicates the highest value that the Server will accept as a Topic Alias sent by the Client. The Server uses this value to limit the number of Topic Aliases that it is willing to hold on this Connection. The Client MUST NOT send a Topic Alias in a PUBLISH packet to the Server greater than this value[MQTT-3.2.2-17]. A value of 0 indicates that the Server does not accept any Topic Aliases on this connection. If Topic Alias Maximum is absent or 0, the Client MUST NOT send any Topic Aliases on to the Server [MQTT-3.2.2-18].

 

Solace Implementation Note

Solace does not support Topic Alias. It never returns a Topic Alias Maximum in its CONNACK, and thus the client MUST NOT send any Topic Aliases.

 

3.2.2.3.9 Reason String

31 (0x1F) Byte Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is a human readable string designed for diagnostics and SHOULD NOT be parsed by the Client.

 

The Server uses this value to give additional information to the Client. The Server MUST NOT send this property if it would increase the size of the CONNACK packet beyond the Maximum Packet Size specified by the Client[MQTT-3.2.2-19]. It is a Protocol Error to include the Reason String more than once.

 

Non-normative comment

Proper uses for the reason string in the Client would include using this information in an exception thrown by the Client code, or writing this string to a log.

 

Solace Implementation Note

Solace never sends a Reason String in any packet sent to the Client.

 

3.2.2.3.10 User Property

38 (0x26) Byte, Identifier of User Property.

Followed by a UTF-8 String Pair. This property can be used to provide additional information to the Client including diagnostic information. The Server MUST NOT send this property if it would increase the size of the CONNACK packet beyond the Maximum Packet Size specified by the Client[MQTT-3.2.2-20]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

The content and meaning of this property is not defined by this specification. The receiver of a CONNACK containing this property MAY ignore it.

 

Solace Implementation Note

Solace does not define any User Properties for the CONNACK packet.

 

3.2.2.3.11 Wildcard Subscription Available

40 (0x28) Byte, Identifier of Wildcard Subscription Available.

Followed by a Byte field. If present, this byte declares whether the Server supports Wildcard Subscriptions. A value is 0 means that Wildcard Subscriptions are not supported. A value of 1 means Wildcard Subscriptions are supported. If not present, then Wildcard Subscriptions are supported. It is a Protocol Error to include the Wildcard Subscription Available more than once or to send a value other than 0 or 1.

 

If the Server receives a SUBSCRIBE packet containing a Wildcard Subscription and it does not support Wildcard Subscriptions, this is a Protocol Error. The Server uses DISCONNECT with Reason Code 0xA2 (Wildcard Subscriptions not supported) as described in section 4.13.

 

If a Server supports Wildcard Subscriptions, it can still reject a particular subscribe request containing a Wildcard Subscription. In this case the Server MAY send a SUBACK Control Packet with a Reason Code 0xA2 (Wildcard Subscriptions not supported).

 

Solace Implementation Note

Solace supports wildcard subscriptions.

 

3.2.2.3.12 Subscription Identifiers Available

41 (0x29) Byte, Identifier of Subscription Identifier Available.

Followed by a Byte field. If present, this byte declares whether the Server supports Subscription Identifiers. A value is 0 means that Subscription Identifiers are not supported. A value of 1 means Subscription Identifiers are supported. If not present, then Subscription Identifiers are supported. It is a Protocol Error to include the Subscription Identifier Available more than once, or to send a value other than 0 or 1.

 

If the Server receives a SUBSCRIBE packet containing Subscription Identifier and it does not support Subscription Identifiers, this is a Protocol Error. The Server uses DISCONNECT with Reason Code of 0xA1 (Subscription Identifiers not supported) as described in section 4.13.

 

Solace Implementation Note

Solace does not support Subscription Identifiers. A value of 0 is always set in the CONNACK.

 

3.2.2.3.13 Shared Subscription Available

42 (0x2A) Byte, Identifier of Shared Subscription Available.

Followed by a Byte field. If present, this byte declares whether the Server supports Shared Subscriptions. A value is 0 means that Shared Subscriptions are not supported. A value of 1 means Shared Subscriptions are supported. If not present, then Shared Subscriptions are supported. It is a Protocol Error to include the Shared Subscription Available more than once or to send a value other than 0 or 1.

 

If the Server receives a SUBSCRIBE packet containing Shared Subscriptions and it does not support Shared Subscriptions, this is a Protocol Error. The Server uses DISCONNECT with Reason Code 0x9E (Shared Subscriptions not supported) as described in section 4.13.

 

Solace Implementation Note

Solace supports shared subscriptions with some caveats. See section 4.8.2 for details.

If the client is not allowed to use shared subscriptions, the broker returns a SUBACK with reason code 0x9E (Shared Subscriptions not supported).

 

3.2.2.3.14 Server Keep Alive

19 (0x13) Byte, Identifier of the Server Keep Alive.

Followed by a Two Byte Integer with the Keep Alive time assigned by the Server. If the Server sends a Server Keep Alive on the CONNACK packet, the Client MUST use this value instead of the Keep Alive value the Client sent on CONNECT[MQTT-3.2.2-21]. If the Server does not send the Server Keep Alive, the Server MUST use the Keep Alive value set by the Client on CONNECT[MQTT-3.2.2-22]. It is a Protocol Error to include the Server Keep Alive more than once.

 

Non-normative comment

The primary use of the Server Keep Alive is for the Server to inform the Client that it will disconnect the Client for inactivity sooner than the Keep Alive specified by the Client.

 

3.2.2.3.15 Response Information

26 (0x1A) Byte, Identifier of the Response Information.

Followed by a UTF-8 Encoded String which is used as the basis for creating a Response Topic. The way in which the Client creates a Response Topic from the Response Information is not defined by this specification. It is a Protocol Error to include the Response Information more than once.

 

Solace Implementation Note

The Response Information returned by Solace SHOULD be used as a prefix by the Client to build topics to be used for the request/response messaging pattern. By using this prefix, response topics will work better with MNR and DMR, and across protocols, and the client is always authorized to use them.

 

If the Client sends a Request Response Information with a value 1, it is OPTIONAL for the Server to send the Response Information in the CONNACK.

 

Non-normative comment

A common use of this is to pass a globally unique portion of the topic tree which is reserved for this Client for at least the lifetime of its Session. This often cannot just be a random name as both the requesting Client and the responding Client need to be authorized to use it. It is normal to use this as the root of a topic tree for a particular Client. For the Server to return this information, it normally needs to be correctly configured. Using this mechanism allows this configuration to be done once in the Server rather than in each Client.

 

Refer to section 4.10 for more information about Request / Response.

 

3.2.2.3.16 Server Reference

28 (0x1C) Byte, Identifier of the Server Reference.

Followed by a UTF-8 Encoded String which can be used by the Client to identify another Server to use. It is a Protocol Error to include the Server Reference more than once.

 

The Server uses a Server Reference in either a CONNACK or DISCONNECT packet with Reason code of 0x9C (Use another server) or Reason Code 0x9D (Server moved) as described in section 4.13.

 

Refer to section 4.11 Server redirection for information about how Server Reference is used.

 

Solace Implementation Note

Solace never returns a Server Reference.

 

3.2.2.3.17 Authentication Method

21 (0x15) Byte, Identifier of the Authentication Method.

Followed by a UTF-8 Encoded String containing the name of the authentication method. It is a Protocol Error to include the Authentication Method more than once. Refer to section 4.12 for more information about extended authentication.

 

Solace Implementation Note

Solace does not support extended authentication.

3.2.2.3.18 Authentication Data

22 (0x16) Byte, Identifier of the Authentication Data.

Followed by Binary Data containing authentication data. The contents of this data are defined by the authentication method and the state of already exchanged authentication data. It is a Protocol Error to include the Authentication Data more than once. Refer to section 4.12 for more information about extended authentication.

3.2.3 CONNACK Payload

The CONNACK packet has no Payload.

3.3 PUBLISH – Publish message

A PUBLISH packet is sent from a Client to a Server or from a Server to a Client to transport an Application Message.

3.3.1 PUBLISH Fixed Header

Figure 3‑8 – PUBLISH packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (3)

DUP flag

QoS level

RETAIN

 

0

0

1

1

X

X

X

X

byte 2…

Remaining Length

3.3.1.1 DUP

Position: byte 1, bit 3.

If the DUP flag is set to 0, it indicates that this is the first occasion that the Client or Server has attempted to send this PUBLISH packet. If the DUP flag is set to 1, it indicates that this might be re-delivery of an earlier attempt to send the packet.

 

The DUP flag MUST be set to 1 by the Client or Server when it attempts to re-deliver a PUBLISH packet [MQTT-3.3.1-1]. The DUP flag MUST be set to 0 for all QoS 0 messages[MQTT-3.3.1-2].

 

The value of the DUP flag from an incoming PUBLISH packet is not propagated when the PUBLISH packet is sent to subscribers by the Server. The DUP flag in the outgoing PUBLISH packet is set independently to the incoming PUBLISH packet, its value MUST be determined solely by whether the outgoing PUBLISH packet is a retransmission[MQTT-3.3.1-3].

 

Non-normative comment

The receiver of an MQTT Control Packet that contains the DUP flag set to 1 cannot assume that it has seen an earlier copy of this packet.

 

Non-normative comment

It is important to note that the DUP flag refers to the MQTT Control Packet itself and not to the Application Message that it contains. When using QoS 1, it is possible for a Client to receive a PUBLISH packet with DUP flag set to 0 that contains a repetition of an Application Message that it received earlier, but with a different Packet Identifier. Section 2.2.1 provides more information about Packet Identifiers.

3.3.1.2 QoS

Position: byte 1, bits 2-1.

This field indicates the level of assurance for delivery of an Application Message. The QoS levels are shown below.

 

Table 3‑2 - QoS definitions

QoS value

Bit 2

bit 1

Description

0

0

0

At most once delivery

1

0

1

At least once delivery

2

1

0

Exactly once delivery

-

1

1

Reserved – must not be used

 

If the Server included a Maximum QoS in its CONNACK response to a Client and it receives a PUBLISH packet with a QoS greater than this, then it uses DISCONNECT with Reason Code 0x9B (QoS not supported) as described in section 4.13 Handling errors.

 

A PUBLISH Packet MUST NOT have both QoS bits set to 1[MQTT-3.3.1-4]. If a Server or Client receives a PUBLISH packet which has both QoS bits set to 1 it is a Malformed Packet. Use DISCONNECT with Reason Code 0x81 (Malformed Packet) as described in section 4.13.

3.3.1.3 RETAIN

Position: byte 1, bit 0.

 

If the RETAIN flag is set to 1 in a PUBLISH packet sent by a Client to a Server, the Server MUST replace any existing retained message for this topic and store the Application Message [MQTT-3.3.1-5], so that it can be delivered to future subscribers whose subscriptions match its Topic Name. If the Payload contains zero bytes it is processed normally by the Server but any retained message with the same topic name MUST be removed and any future subscribers for the topic will not receive a retained message[MQTT-3.3.1-6]. A retained message with a Payload containing zero bytes MUST NOT be stored as a retained message on the Server[MQTT-3.3.1-7].

 

If the RETAIN flag is 0 in a PUBLISH packet sent by a Client to a Server, the Server MUST NOT store the message as a retained message and MUST NOT remove or replace any existing retained message[MQTT-3.3.1-8].

 

If the Server included Retain Available in its CONNACK response to a Client with its value set to 0 and it receives a PUBLISH packet with the RETAIN flag is set to 1, then it uses the DISCONNECT Reason Code of 0x9A (Retain not supported) as described in section 4.13.

 

When a new Non‑shared Subscription is made, the last retained message, if any, on each matching topic name is sent to the Client as directed by the Retain Handling Subscription Option. These messages are sent with the RETAIN flag set to 1. Which retained messages are sent is controlled by the Retain Handling Subscription Option. At the time of the Subscription:

  • If Retain Handling is set to 0 the Server MUST send the retained messages matching the Topic Filter of the subscription to the Client[MQTT-3.3.1-9].
  • If Retain Handling is set to 1 then if the subscription did not already exist, the Server MUST send all retained message matching the Topic Filter of the subscription to the Client, and if the subscription did exist the Server MUST NOT send the retained messages.[MQTT-3.3.1-10].
  • If Retain Handling is set to 2, the Server MUST NOT send the retained messages[MQTT-3.3.1-11].

 

Solace Implementation Note

Solace only supports Retain Handling of 0.

Support for MQTT Retained Messages is a Controlled Availability (CA) feature. Please contact Solace to find out if this feature is supported for your use case.

 

Refer to section 3.8.3.1 for a definition of the Subscription Options.

If the Server receives a PUBLISH packet with the RETAIN flag set to 1, and QoS 0 it SHOULD store the new QoS 0 message as the new retained message for that topic, but MAY choose to discard it at any time. If this happens there will be no retained message for that topic.

If the current retained message for a Topic expires, it is discarded and there will be no retained message for that topic.

Solace Implementation Note

Solace does not expire retained messages.

 

The setting of the RETAIN flag in an Application Message forwarded by the Server from an established connection is controlled by the Retain As Published subscription option. Refer to section 3.8.3.1 for a definition of the Subscription Options.

 

  • If the value of Retain As Published subscription option is set to 0, the Server MUST set the RETAIN flag to 0 when forwarding an Application Message regardless of how the RETAIN flag was set in the received PUBLISH packet[MQTT-3.3.1-12].
  • If the value of Retain As Published subscription option is set to 1, the Server MUST set the RETAIN flag equal to the RETAIN flag in the received PUBLISH packet[MQTT-3.3.1-13].

Solace Implementation Note

Solace only supports Retain As Published of 0.

 

Non-normative comment

Retained messages are useful where publishers send state messages on an irregular basis. A new non-shared subscriber will receive the most recent state.

3.3.1.4 Remaining Length

This is the length of Variable Header plus the length of the Payload, encoded as a Variable Byte Integer.

3.3.2 PUBLISH Variable Header

The Variable Header of the PUBLISH Packet contains the following fields in the order: Topic Name, Packet Identifier, and Properties. The rules for encoding Properties are described in section 2.2.2.

3.3.2.1 Topic Name

The Topic Name identifies the information channel to which Payload data is published.

 

The Topic Name MUST be present as the first field in the PUBLISH packet Variable Header. It MUST be a UTF-8 Encoded String as defined in section 1.5.4[MQTT-3.3.2-1].

 

The Topic Name in the PUBLISH packet MUST NOT contain wildcard characters [MQTT-3.3.2-2].

 

The Topic Name in a PUBLISH packet sent by a Server to a subscribing Client MUST match the Subscription’s Topic Filter according to the matching process defined in section 4.7[MQTT-3.3.2-3]. However, as the Server is permitted to map the Topic Name to another name, it might not be the same as the Topic Name in the original PUBLISH packet.

 

Solace Implementation Note

Topic Name must be from 1 to 250 characters in length with at most 128 levels.  Topics outside these bounds cause the connection to be closed.

 

To reduce the size of the PUBLISH packet the sender can use a Topic Alias. The Topic Alias is described in section 3.3.2.3.4. It is a Protocol Error if the Topic Name is zero length and there is no Topic Alias.

3.3.2.2 Packet Identifier

The Packet Identifier field is only present in PUBLISH packets where the QoS level is 1 or 2. Section 2.2.1 provides more information about Packet Identifiers.

3.3.2.3 PUBLISH Properties

3.3.2.3.1 Property Length

The length of the Properties in the PUBLISH packet Variable Header encoded as a Variable Byte Integer.

3.3.2.3.2 Payload Format Indicator

1 (0x01) Byte, Identifier of the Payload Format Indicator.

Followed by the value of the Payload Format Indicator, either of:

  • 0 (0x00) Byte Indicates that the Payload is unspecified bytes, which is equivalent to not sending a Payload Format Indicator.
  • 1 (0x01) Byte Indicates that the Payload is UTF-8 Encoded Character Data. The UTF-8 data in the Payload MUST be well-formed UTF-8 as defined by the Unicode specification [Unicode] and restated in RFC 3629 [RFC3629].

 

A Server MUST send the Payload Format Indicator unaltered to all subscribers receiving the Application Message[MQTT-3.3.2-4]. The receiver MAY validate that the Payload is of the format indicated, and if it is not send a PUBACK, PUBREC, or DISCONNECT with Reason Code of 0x99 (Payload format invalid) as described in section 4.13.  Refer to section 5.4.9 for information about security issues in validating the payload format.

3.3.2.3.3 Message Expiry Interval

2 (0x02) Byte, Identifier of the Message Expiry Interval.

Followed by the Four Byte Integer representing the Message Expiry Interval.

 

If present, the Four Byte value is the lifetime of the Application Message in seconds. If the Message Expiry Interval has passed and the Server has not managed to start onward delivery to a matching subscriber, then it MUST delete the copy of the message for that subscriber[MQTT-3.3.2-5].

 

If absent, the Application Message does not expire.

The PUBLISH packet sent to a Client by the Server MUST contain a Message Expiry Interval set to the received value minus the time that the Application Message has been waiting in the Server[MQTT-3.3.2-6].

Refer to section 4.1 for details and limitations of stored state.

 

Solace Implementation Note

Message Expiry Interval is not acted upon for a QoS 0 PUBLISH. The received value is passed on unmodified to clients. In addition, the expiry interval is limited to approximately 10 years. Any interval longer than this is truncated to 10 years.

3.3.2.3.4 Topic Alias

35 (0x23) Byte, Identifier of the Topic Alias.

Followed by the Two Byte integer representing the Topic Alias value. It is a Protocol Error to include the Topic Alias value more than once.

 

A Topic Alias is an integer value that is used to identify the Topic instead of using the Topic Name. This reduces the size of the PUBLISH packet, and is useful when the Topic Names are long and the same Topic Names are used repetitively within a Network Connection.

 

The sender decides whether to use a Topic Alias and chooses the value. It sets a Topic Alias mapping by including a non-zero length Topic Name and a Topic Alias in the PUBLISH packet. The receiver processes the PUBLISH as normal but also sets the specified Topic Alias mapping to this Topic Name.

 

If a Topic Alias mapping has been set at the receiver, a sender can send a PUBLISH packet that contains that Topic Alias and a zero length Topic Name. The receiver then treats the incoming PUBLISH as if it had contained the Topic Name of the Topic Alias.

 

A sender can modify the Topic Alias mapping by sending another PUBLISH in the same Network Connection with the same Topic Alias value and a different non-zero length Topic Name.

 

Topic Alias mappings exist only within a Network Connection and last only for the lifetime of that Network Connection. A receiver MUST NOT carry forward any Topic Alias mappings from one Network Connection to another[MQTT-3.3.2-7].

 

A Topic Alias of 0 is not permitted. A sender MUST NOT send a PUBLISH packet containing a Topic Alias which has the value 0[MQTT-3.3.2-8].

 

A Client MUST NOT send a PUBLISH packet with a Topic Alias greater than the Topic Alias Maximum value returned by the Server in the CONNACK packet[MQTT-3.3.2-9]. A Client MUST accept all Topic Alias values greater than 0 and less than or equal to the Topic Alias Maximum value that it sent in the CONNECT packet[MQTT-3.3.2-10].

 

A Server MUST NOT send a PUBLISH packet with a Topic Alias greater than the Topic Alias Maximum value sent by the Client in the CONNECT packet[MQTT-3.3.2-11]. A Server MUST accept all Topic Alias values greater than 0 and less than or equal to the Topic Alias Maximum value that it returned in the CONNACK packet[MQTT-3.3.2-12].

 

The Topic Alias mappings used by the Client and Server are independent from each other. Thus, when a Client sends a PUBLISH containing a Topic Alias value of 1 to a Server and the Server sends a PUBLISH with a Topic Alias value of 1 to that Client they will in general be referring to different Topics.

 

Solace Implementation Note

Solace does not support Topic Aliasing.

3.3.2.3.5 Response Topic

8 (0x08) Byte, Identifier of the Response Topic.

Followed by a UTF-8 Encoded String which is used as the Topic Name for a response message. The Response Topic MUST be a UTF-8 Encoded String as defined in section 1.5.4 [MQTT-3.3.2-13]. The Response Topic MUST NOT contain wildcard characters [MQTT-3.3.2-14]. It is a Protocol Error to include the Response Topic more than once. The presence of a Response Topic identifies the Message as a Request.

 

Refer to section 4.10 for more information about Request / Response.

 

The Server MUST send the Response Topic unaltered to all subscribers receiving the Application Message[MQTT-3.3.2-15].

 

Non-normative comment:

The receiver of an Application Message with a Response Topic sends a response by using the Response Topic as the Topic Name of a PUBLISH. If the Request Message contains a Correlation Data, the receiver of the Request Message should also include this Correlation Data as a property in the PUBLISH packet of the Response Message.

3.3.2.3.6 Correlation Data

9 (0x09) Byte, Identifier of the Correlation Data.

Followed by Binary Data. The Correlation Data is used by the sender of the Request Message to identify which request the Response Message is for when it is received. It is a Protocol Error to include Correlation Data more than once. If the Correlation Data is not present, the Requester does not require any correlation data.

 

The Server MUST send the Correlation Data unaltered to all subscribers receiving the Application Message[MQTT-3.3.2-16]. The value of the Correlation Data only has meaning to the sender of the Request Message and receiver of the Response Message.

 

Non-normative comment

The receiver of an Application Message which contains both a Response Topic and a Correlation Data sends a response by using the Response Topic as the Topic Name of a PUBLISH. The Client should also send the Correlation Data unaltered as part of the PUBLISH of the responses.

 

Non-normative comment

If the Correlation Data contains information which can cause application failures if modified by the Client responding to the request, it should be encrypted and/or hashed to allow any alteration to be detected.

 

Refer to section 4.10 for more information about Request / Response

 

3.3.2.3.7 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by a UTF-8 String Pair. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

The Server MUST send all User Properties unaltered in a PUBLISH packet when forwarding the Application Message to a Client[MQTT-3.3.2-17]. The Server MUST maintain the order of User Properties when forwarding the Application Message[MQTT-3.3.2-18].

 

Solace Implementation Note

There is no limit to the number of MQTT user properties in a PUBLISH message received by the Solace server. There is a limit of 96 to the number of MQTT user properties in a PUBLISH message sent by the Solace server.

 

Non-normative comment

This property is intended to provide a means of transferring application layer name-value tags whose meaning and interpretation are known only by the application programs responsible for sending and receiving them.

 

3.3.2.3.8 Subscription Identifier

11 (0x0B), Identifier of the Subscription Identifier.

Followed by a Variable Byte Integer representing the identifier of the subscription.

 

The Subscription Identifier can have the value of 1 to 268,435,455. It is a Protocol Error if the Subscription Identifier has a value of 0. Multiple Subscription Identifiers will be included if the publication is the result of a match to more than one subscription, in this case their order is not significant.

 

Solace Implementation Note

Solace does not support Subscription Identifiers.

3.3.2.3.9 Content Type

3 (0x03) Identifier of the Content Type.

Followed by a UTF-8 Encoded String describing the content of the Application Message. The Content Type MUST be a UTF-8 Encoded String as defined in section 1.5.4[MQTT-3.3.2-19].

It is a Protocol Error to include the Content Type more than once. The value of the Content Type is defined by the sending and receiving application.

 

A Server MUST send the Content Type unaltered to all subscribers receiving the Application Message[MQTT-3.3.2-20].

 

Non-normative comment

The UTF-8 Encoded String may use a MIME content type string to describe the contents of the Application message. However, since the sending and receiving applications are responsible for the definition and interpretation of the string, MQTT performs no validation of the string except to insure it is a valid UTF-8 Encoded String.

 

Non-normative example

Figure 3-9 shows an example of a PUBLISH packet with the Topic Name set to “a/b”, the Packet Identifier set to 10, and having no properties.

 

Figure 3‑9 - PUBLISH packet Variable Header non-normative example

 

Description

7

6

5

4

3

2

1

0

Topic Name

byte 1

Length MSB (0)

0

0

0

0

0

0

0

0

byte 2

Length LSB (3)

0

0

0

0

0

0

1

1

byte 3

‘a’ (0x61)

0

1

1

0

0

0

0

1

byte 4

‘/’ (0x2F)

0

0

1

0

1

1

1

1

byte 5

‘b’ (0x62)

0

1

1

0

0

0

1

0

Packet Identifier

byte 6

Packet Identifier MSB (0)

0

0

0

0

0

0

0

0

byte 7

Packet Identifier LSB (10)

0

0

0

0

1

0

1

0

Property Length

byte 8

No Properties

0

0

0

0

0

0

0

0

3.3.3 PUBLISH Payload

The Payload contains the Application Message that is being published. The content and format of the data is application specific. The length of the Payload can be calculated by subtracting the length of the Variable Header from the Remaining Length field that is in the Fixed Header. It is valid for a PUBLISH packet to contain a zero length Payload.

Solace Implementation Note

Solace has limits to the size of a message, depending on the message QoS and the type of event broker.

When a Solace server receives a message whose length and QoS combination exceeds these limits, the connection is closed and an appropriate log is raised. Note that the Solace PubSub+ event broker administrator may configure lower limits than these.

3.3.4 PUBLISH Actions

The receiver of a PUBLISH Packet MUST respond with the packet as determined by the QoS in the PUBLISH Packet[MQTT-3.3.4-1].

 

Table 3‑3 Expected PUBLISH packet response

QoS Level

Expected Response

QoS 0

None

QoS 1

PUBACK packet

QoS 2

PUBREC packet

 

The Client uses a PUBLISH packet to send an Application Message to the Server, for distribution to Clients with matching subscriptions.

 

The Server uses a PUBLISH packet to send an Application Message to each Client which has a matching subscription. The PUBLISH packet includes the Subscription Identifier carried in the SUBSCRIBE packet, if there was one.

 

When Clients make subscriptions with Topic Filters that include wildcards, it is possible for a Client’s subscriptions to overlap so that a published message might match multiple filters. In this case the Server MUST deliver the message to the Client respecting the maximum QoS of all the matching subscriptions[MQTT-3.3.4-2]. In addition, the Server MAY deliver further copies of the message, one for each additional matching subscription and respecting the subscription’s QoS in each case.

Solace Implementation Note

When the Solace server delivers the message to the Client, it will respect the maximum QoS of all the matching subscriptions. In addition, if there is one or more QoS 1 subscriptions and one or more QoS 0 subscriptions that overlap, then the Solace server will deliver two instances of the message – one for each QoS level.

If a Client receives an unsolicited Application Message (not resulting from a subscription) which has a QoS greater than Maximum QoS, it uses a DISCONNECT packet with Reason Code 0x9B (QoS not supported ) as described in section 4.13 Handling errors.

If the Client specified a Subscription Identifier for any of the overlapping subscriptions the Server MUST send those Subscription Identifiers in the message which is published as the result of the subscriptions[MQTT-3.3.4-3]. If the Server sends a single copy of the message it MUST include in the PUBLISH packet the Subscription Identifiers for all matching subscriptions which have a Subscription Identifiers, their order is not significant[MQTT-3.3.4-4]. If the Server sends multiple PUBLISH packets it MUST send, in each of them, the Subscription Identifier of the matching subscription if it has a Subscription Identifier[MQTT-3.3.4-5].

 

It is possible that the Client made several subscriptions which match a publication and that it used the same identifier for more than one of them. In this case the PUBLISH packet will carry multiple identical Subscription Identifiers.

 

It is a Protocol Error for a PUBLISH packet to contain any Subscription Identifier other than those received in SUBSCRIBE packet which caused it to flow. A PUBLISH packet sent from a Client to a Server MUST NOT contain a Subscription Identifier[MQTT-3.3.4-6].

 

If the subscription was shared, then only the Subscription Identifiers that were present in the SUBSCRIBE packet from the Client which is receiving the message are returned in the PUBLISH packet.

 

The action of the recipient when it receives a PUBLISH packet depends on the QoS level as described in section 4.3.

 

Solace Implementation Note

The Solace server does not fully support the two-phase commit semantics of receiving a PUBLISH packet with QoS 2.  However, to provide maximum interoperability, as allowed by the above section, the Solace server responds to a PUBLISH packet with QoS 2 (that is, the Solace server will respond to a received QoS 2 PUBLISH packet with a PUBREC packet, and will respond to a received PUBREL packet with a PUBCOMP packet). This response effectively provides the same quality of service treatment as a QoS 1 message.

 

If the PUBLISH packet contains a Topic Alias, the receiver processes it as follows:

  1. A Topic Alias value of 0 or greater than the Maximum Topic Alias is a Protocol Error, the receiver uses DISCONNECT with Reason Code of 0x94 (Topic Alias invalid) as described in section 4.13.
     
  2. If the receiver has already established a mapping for the Topic Alias, then
    1. If the packet has a zero length Topic Name, the receiver processes it using the Topic Name that corresponds to the Topic Alias
    2. If the packet contains a non-zero length Topic Name, the receiver processes the packet using that Topic Name and updates its mapping for the Topic Alias to the Topic Name from the incoming packet

  3. If the receiver does not already have a mapping for this Topic Alias
    1. If the packet has a zero length Topic Name field it is a Protocol Error and the receiver uses DISCONNECT with Reason Code of 0x82 (Protocol Error) as described in section 4.13.
    2. If the packet contains a Topic Name with a non-zero length, the receiver processes the packet using that Topic Name and sets its mappings for the Topic Alias to Topic Name from the incoming packet.

 

Non-normative Comment

If the Server distributes Application Messages to Clients at different protocol levels (such as MQTT V3.1.1) which do not support properties or other features provided by this specification, some information in the Application Message can be lost, and applications which depend on this information might not work correctly.

 

The Client MUST NOT send more than Receive Maximum QoS 1 and QoS 2 PUBLISH packets for which it has not received PUBACK, PUBCOMP, or PUBREC with a Reason Code of 128 or greater from the Server[MQTT-3.3.4-7]. If it receives more than Receive Maximum QoS 1 and QoS 2 PUBLISH packets where it has not sent a PUBACK or PUBCOMP in response, the Server uses a DISCONNECT packet with Reason Code 0x93 (Receive Maximum exceeded) as described in section 4.13 Handling errors. Refer to section 4.9 for more information about flow control.

 

The Client MUST NOT delay the sending of any packets other than PUBLISH packets due to having sent Receive Maximum PUBLISH packets without receiving acknowledgements for them [MQTT-3.3.4-8]. The value of Receive Maximum applies only to the current Network Connection.

 

Non-normative comment

The Client might choose to send fewer than Receive Maximum messages to the Server without receiving acknowledgement, even if it has more than this number of messages available to send.

 

Non-normative comment

The Client might choose to suspend the sending of QoS 0 PUBLISH packets when it suspends the sending of QoS 1 and QoS 2 PUBLISH packets.

 

Non-normative comment

If the Client sends QoS 1 or QoS 2 PUBLISH packets before it has received a CONNACK packet, it risks being disconnected because it has sent more than Receive Maximum publications.

 

The Server MUST NOT send more than Receive Maximum QoS 1 and QoS 2 PUBLISH packets for which it has not received PUBACK, PUBCOMP, or PUBREC with a Reason Code of 128 or greater from the Client[MQTT-3.3.4-9]. If it receives more than Receive Maximum QoS 1 and QoS 2 PUBLISH packets where it has not sent a PUBACK or PUBCOMP in response, the Client uses DISCONNECT with Reason Code 0x93 (Receive Maximum exceeded) as described in section 4.13 Handling errors. Refer to section 4.9 for more information about flow control.

 

The Server MUST NOT delay the sending of any packets other than PUBLISH packets due to having sent Receive Maximum PUBLISH packets without receiving acknowledgements for them [MQTT-3.3.4-10].

 

Non-normative comment

The Server might choose to send fewer than Receive Maximum messages to the Client without receiving acknowledgement, even if it has more than this number of messages available to send.

 

Non-normative comment

The Server might choose to suspend the sending of QoS 0 PUBLISH packets when it suspends the sending of QoS 1 and QoS 2 PUBLISH packets.

3.4 PUBACK – Publish acknowledgement

A PUBACK packet is the response to a PUBLISH packet with QoS 1.

3.4.1 PUBACK Fixed Header

Figure 3‑10 - PUBACK packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (4)

Reserved

 

0

1

0

0

0

0

0

0

byte 2

Remaining Length

 

Remaining Length field

This is the length of the Variable Header, encoded as a Variable Byte Integer.

3.4.2 PUBACK Variable Header

The Variable Header of the PUBACK Packet contains the following fields in the order: Packet Identifier from the PUBLISH packet that is being acknowledged, PUBACK Reason Code, Property Length, and the Properties. The rules for encoding Properties are described in section 2.2.2.

Figure 3‑11 – PUBACK packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

byte 3

PUBACK Reason Code

byte 4

Property Length

3.4.2.1 PUBACK Reason Code

Byte 3 in the Variable Header is the PUBACK Reason Code. If the Remaining Length is 2, then there is no Reason Code and the value of 0x00 (Success) is used.

 

Table 3‑4 - PUBACK Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Success

The message is accepted. Publication of the QoS 1 message proceeds.

16

0x10

No matching subscribers

The message is accepted but there are no subscribers. This is sent only by the Server. If the Server knows that there are no matching subscribers, it MAY use this Reason Code instead of 0x00 (Success).

128

0x80

Unspecified error

The receiver does not accept the publish but either does not want to reveal the reason, or it does not match one of the other values.

131

0x83

Implementation specific error

The PUBLISH is valid but the receiver is not willing to accept it.

135

0x87

Not authorized

The PUBLISH is not authorized.

144

0x90

Topic Name invalid

The Topic Name is not malformed, but is not accepted by this Client or Server.

145

0x91

Packet identifier in use

The Packet Identifier is already in use. This might indicate a mismatch in the Session State between the Client and Server.

151

0x97

Quota exceeded

An implementation or administrative imposed limit has been exceeded.

153

0x99

Payload format invalid

The payload format does not match the specified Payload Format Indicator.

 

The Client or Server sending the PUBACK packet MUST use one of the PUBACK Reason Codes[MQTT-3.4.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. In this case the PUBACK has a Remaining Length of 2.

3.4.2.2 PUBACK Properties

3.4.2.2.1 Property Length

The length of the Properties in the PUBACK packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used.

 

3.4.2.2.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is a human readable string designed for diagnostics and is not intended to be parsed by the receiver.

 

The sender uses this value to give additional information to the receiver. The sender MUST NOT send this property if it would increase the size of the PUBACK packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.4.2-2]. It is a Protocol Error to include the Reason String more than once.

3.4.2.2.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information. The sender MUST NOT send this property if it would increase the size of the PUBACK packet beyond the Maximum Packet Size specified by the receiver [MQTT-3.4.2-3]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

3.4.3 PUBACK Payload

The PUBACK packet has no Payload.

3.4.4 PUBACK Actions

This is described in section 4.3.2.

3.5 PUBREC – Publish received (QoS 2 delivery part 1)

A PUBREC packet is the response to a PUBLISH packet with QoS 2. It is the second packet of the QoS 2 protocol exchange.

3.5.1 PUBREC Fixed Header

Figure 3‑12 - PUBREC packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (5)

Reserved

 

0

1

0

1

0

0

0

0

byte 2

Remaining Length

Remaining Length field

This is the length of the Variable Header, encoded as a Variable Byte Integer.

3.5.2 PUBREC Variable Header

The Variable Header of the PUBREC Packet consists of the following fields in the order: the Packet Identifier from the PUBLISH packet that is being acknowledged, PUBREC Reason Code, and Properties. The rules for encoding Properties are described in section 2.2.2.

 

 Figure 3‑13 - PUBREC packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

byte 3

PUBREC Reason Code

byte 4

Property Length

3.5.2.1 PUBREC Reason Code

Byte 3 in the Variable Header is the PUBREC Reason Code. If the Remaining Length is 2, then the Publish Reason Code has the value 0x00 (Success).

 

Table 3‑5 – PUBREC Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Success

The message is accepted. Publication of the QoS 2 message proceeds.

16

0x10

No matching subscribers.

The message is accepted but there are no subscribers. This is sent only by the Server. If the Server knows that there are no matching subscribers, it MAY use this Reason Code instead of 0x00 (Success).

128

0x80

Unspecified error

The receiver does not accept the publish but either does not want to reveal the reason, or it does not match one of the other values.

131

0x83

Implementation specific error

The PUBLISH is valid but the receiver is not willing to accept it.

135

0x87

Not authorized

The PUBLISH is not authorized.

144

0x90

Topic Name invalid

The Topic Name is not malformed, but is not accepted by this Client or Server.

145

0x91

Packet Identifier in use

The Packet Identifier is already in use. This might indicate a mismatch in the Session State between the Client and Server.

151

0x97

Quota exceeded

An implementation or administrative imposed limit has been exceeded.

153

0x99

Payload format invalid

The payload format does not match the one specified in the Payload Format Indicator.

 

The Client or Server sending the PUBREC packet MUST use one of the PUBREC Reason Code values.[MQTT-3.5.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. In this case the PUBREC has a Remaining Length of 2.

3.5.2.2 PUBREC Properties

3.5.2.2.1 Property Length

The length of the Properties in the PUBREC packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used.

3.5.2.2.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is human readable, designed for diagnostics and SHOULD NOT be parsed by the receiver.

 

The sender uses this value to give additional information to the receiver. The sender MUST NOT send this property if it would increase the size of the PUBREC packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.5.2-2]. It is a Protocol Error to include the Reason String more than once.

3.5.2.2.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information. The sender MUST NOT send this property if it would increase the size of the PUBREC packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.5.2-3]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

3.5.3 PUBREC Payload

The PUBREC packet has no Payload.

3.5.4 PUBREC Actions

This is described in section 4.3.3.

3.6 PUBREL – Publish release (QoS 2 delivery part 2)

A PUBREL packet is the response to a PUBREC packet. It is the third packet of the QoS 2 protocol exchange.

3.6.1 PUBREL Fixed Header

Figure 3‑14 – PUBREL packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (6)

Reserved

 

0

1

1

0

0

0

1

0

byte 2

Remaining Length

 

Bits 3,2,1 and 0 of the Fixed Header in the PUBREL packet are reserved and MUST be set to 0,0,1 and 0 respectively. The Server MUST treat any other value as malformed and close the Network Connection[MQTT-3.6.1-1].

 

Remaining Length field

This is the length of the Variable Header, encoded as a Variable Byte Integer.

3.6.2 PUBREL Variable Header

The Variable Header of the PUBREL Packet contains the following fields in the order: the Packet Identifier from the PUBREC packet that is being acknowledged, PUBREL Reason Code, and Properties. The rules for encoding Properties are described in section 2.2.2.

 

 Figure 3‑15 – PUBREL packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

byte 3

PUBREL Reason Code

byte 4

Property Length

3.6.2.1 PUBREL Reason Code

Byte 3 in the Variable Header is the PUBREL Reason Code. If the Remaining Length is 2, the value of 0x00 (Success) is used.

 

Table 3‑6 - PUBREL Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Success

Message released.

146

0x92

Packet Identifier not found

The Packet Identifier is not known. This is not an error during recovery, but at other times indicates a mismatch between the Session State on the Client and Server.

 

The Client or Server sending the PUBREL packet MUST use one of the PUBREL Reason Code values[MQTT-3.6.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. In this case the PUBREL has a Remaining Length of 2.

3.6.2.2 PUBREL Properties

3.6.2.2.1 Property Length

The length of the Properties in the PUBREL packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used.

3.6.2.2.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is human readable, designed for diagnostics and SHOULD NOT be parsed by the receiver.

 

The sender uses this value to give additional information to the receiver. The sender MUST NOT send this Property if it would increase the size of the PUBREL packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.6.2-2]. It is a Protocol Error to include the Reason String more than once.

3.6.2.2.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information for the PUBREL. The sender MUST NOT send this property if it would increase the size of the PUBREL packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.6.2-3]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

3.6.3 PUBREL Payload

The PUBREL packet has no Payload.

3.6.4 PUBREL Actions

This is described in section 4.3.3.

3.7 PUBCOMP – Publish complete (QoS 2 delivery part 3)

The PUBCOMP packet is the response to a PUBREL packet. It is the fourth and final packet of the QoS 2 protocol exchange.

3.7.1 PUBCOMP Fixed Header

Figure 3‑16 – PUBCOMP packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control packet type (7)

Reserved

 

0

1

1

1

0

0

0

0

byte 2

Remaining Length

 

Remaining Length field

This is the length of the Variable Header, encoded as a Variable Byte Integer.

3.7.2 PUBCOMP Variable Header

The Variable Header of the PUBCOMP Packet contains the following fields in the order: Packet Identifier from the PUBREL packet that is being acknowledged, PUBCOMP Reason Code, and Properties. The rules for encoding Properties are described in section 2.2.2.

 

Figure 3‑17 - PUBCOMP packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

byte 3

PUBCOMP Reason Code

byte 4

Property Length

3.7.2.1 PUBCOMP Reason Code

Byte 3 in the Variable Header is the PUBCOMP Reason Code. If the Remaining Length is 2, then the value 0x00 (Success) is used.

 

Table 3‑7 – PUBCOMP Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Success

Packet Identifier released. Publication of QoS 2 message is complete.

146

0x92

Packet Identifier not found

The Packet Identifier is not known. This is not an error during recovery, but at other times indicates a mismatch between the Session State on the Client and Server.

 

The Client or Server sending the PUBCOMP packet MUST use one of the PUBCOMP Reason Code values[MQTT-3.7.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. In this case the PUBCOMP has a Remaining Length of 2.

3.7.2.2 PUBCOMP Properties

3.7.2.2.1 Property Length

The length of the Properties in the PUBCOMP packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used.

3.7.2.2.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is a human readable string designed for diagnostics and SHOULD NOT be parsed by the receiver.

 

The sender uses this value to give additional information to the receiver. The sender MUST NOT send this Property if it would increase the size of the PUBCOMP packet beyond the Maximum Packet Size specified by the receiver[MQTT-3.7.2-2]. It is a Protocol Error to include the Reason String more than once.

 

3.7.2.2.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information. The sender MUST NOT send this property if it would increase the size of the PUBCOMP packet beyond the Maximum Packet Size specified by the receiver [MQTT-3.7.2-3]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

3.7.3 PUBCOMP Payload

The PUBCOMP packet has no Payload.

3.7.4 PUBCOMP Actions

This is described in section 4.3.3.

3.8 SUBSCRIBE - Subscribe request

The SUBSCRIBE packet is sent from the Client to the Server to create one or more Subscriptions. Each Subscription registers a Client’s interest in one or more Topics. The Server sends PUBLISH packets to the Client to forward Application Messages that were published to Topics that match these Subscriptions. The SUBSCRIBE packet also specifies (for each Subscription) the maximum QoS with which the Server can send Application Messages to the Client.

3.8.1 SUBSCRIBE Fixed Header

Figure 3‑18 SUBSCRIBE packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (8)

Reserved

 

1

0

0

0

0

0

1

0

byte 2

Remaining Length

 

Bits 3,2,1 and 0 of the Fixed Header of the SUBSCRIBE packet are reserved and MUST be set to 0,0,1 and 0 respectively. The Server MUST treat any other value as malformed and close the Network Connection[MQTT-3.8.1-1].

 

Remaining Length field

This is the length of Variable Header plus the length of the Payload, encoded as a Variable Byte Integer.

3.8.2 SUBSCRIBE Variable Header

The Variable Header of the SUBSCRIBE Packet contains the following fields in the order: Packet Identifier, and Properties. Section 2.2.1 provides more information about Packet Identifiers. The rules for encoding Properties are described in section 2.2.2.

 

Non-normative example

Figure 3-19 shows an example of a SUBSCRIBE variable header with a Packet Identifier of 10 and no properties.

 

Figure 3‑19 – SUBSCRIBE Variable Header example

 

Description

7

6

5

4

3

2

1

0

Packet Identifier

byte 1

Packet Identifier MSB (0)

0

0

0

0

0

0

0

0

byte 2

Packet Identifier LSB (10)

0

0

0

0

1

0

1

0

byte 3

Property Length (0)

0

0

0

0

0

0

0

0

3.8.2.1 SUBSCRIBE Properties

3.8.2.1.1 Property Length

The length of Properties in the SUBSCRIBE packet Variable Header encoded as a Variable Byte Integer.

3.8.2.1.2 Subscription Identifier

11 (0x0B) Byte, Identifier of the Subscription Identifier.

Followed by a Variable Byte Integer representing the identifier of the subscription. The Subscription Identifier can have the value of 1 to 268,435,455. It is a Protocol Error if the Subscription Identifier has a value of 0. It is a Protocol Error to include the Subscription Identifier more than once.

 

The Subscription Identifier is associated with any subscription created or modified as the result of this SUBSCRIBE packet. If there is a Subscription Identifier, it is stored with the subscription. If this property is not specified, then the absence of a Subscription Identifier is stored with the subscription.

 

Refer to section 3.8.3.1 for more information about the handling of Subscription Identifiers.

 

Solace Implementation Note

Solace does not support Subscription Identifiers, and indicates this in the CONNACK sent to the client.

 

3.8.2.1.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by a UTF-8 String Pair.

 

The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

Non-normative comment

User Properties on the SUBSCRIBE packet can be used to send subscription related properties from the Client to the Server. The meaning of these properties is not defined by this specification.

 

Solace Implementation Note

Solace does not define any User Properties for a SUBSCRIBE packet.

3.8.3 SUBSCRIBE Payload

The Payload of a SUBSCRIBE packet contains a list of Topic Filters indicating the Topics to which the Client wants to subscribe. The Topic Filters MUST be a UTF-8 Encoded String [MQTT-3.8.3-1]. Each Topic Filter is followed by a Subscription Options byte.

 

The Payload MUST contain at least one Topic Filter and Subscription Options pair[MQTT-3.8.3-2]. A SUBSCRIBE packet with no Payload is a Protocol Error. Refer to section 4.13 for information about handling errors.

 

Solace Implementation Note

  • The Topic Filter must conform to the Solace limitations. Topics outside these are rejected with a SUBACK containing the value 0x80 to indicate failure.
  • SUBSCRIBE packets can contain at most 1,024 Topic Filters. Exceeding this limit will cause the connection to be closed.

3.8.3.1 Subscription Options

Bits 0 and 1 of the Subscription Options represent Maximum QoS field. This gives the maximum QoS level at which the Server can send Application Messages to the Client. It is a Protocol Error if the Maximum QoS field has the value 3.

 

Bit 2 of the Subscription Options represents the No Local option. If the value is 1, Application Messages MUST NOT be forwarded to a connection with a ClientID equal to the ClientID of the publishing connection[MQTT-3.8.3-3].It is a Protocol Error to set the No Local bit to 1 on a Shared Subscription [MQTT-3.8.3-4].

 

Bit 3 of the Subscription Options represents the Retain As Published option. If 1, Application Messages forwarded using this subscription keep the RETAIN flag they were published with. If 0, Application Messages forwarded using this subscription have the RETAIN flag set to 0. Retained messages sent when the subscription is established have the RETAIN flag set to 1.

 

Bits 4 and 5 of the Subscription Options represent the Retain Handling option. This option specifies whether retained messages are sent when the subscription is established. This does not affect the sending of retained messages at any point after the subscribe. If there are no retained messages matching the Topic Filter, all of these values act the same. The values are:

0 = Send retained messages at the time of the subscribe

1 = Send retained messages at subscribe only if the subscription does not currently exist

2 = Do not send retained messages at the time of the subscribe

It is a Protocol Error to send a Retain Handling value of 3.

 

Bits 6 and 7 of the Subscription Options byte are reserved for future use. The Server MUST treat a SUBSCRIBE packet as malformed if any of Reserved bits in the Payload are non-zero[MQTT-3.8.3-5].

 

Solace Implementation Note

Solace does not support the No Local, Retain as Published, and Retain Handling options with any value other than 0. If any of these options are non-zero, the Solace server closes the connection.

 

Non-normative comment

The No Local and Retain As Published subscription options can be used to implement bridging where the Client is sending the message on to another Server.

 

Non-normative comment

Not sending retained messages for an existing subscription is useful when a reconnect is done and the Client is not certain whether the subscriptions were completed in the previous connection to the Session.

 

Non-normative comment

Not sending stored retained messages because of a new subscription is useful where a Client wishes to receive change notifications and does not need to know the initial state.

 

Non-normative comment

For a Server that indicates it does not support retained messages, all valid values of Retain As Published and Retain Handling give the same result which is to not send any retained messages at subscribe and to set the RETAIN flag to 0 for all messages.

 

Figure 3‑20– SUBSCRIBE packet Payload format

Description

7

6

5

4

3

2

1

0

Topic Filter

byte 1

Length MSB

byte 2

Length LSB

bytes 3..N

Topic Filter

Subscription Options

 

Reserved

Retain Handling

RAP

NL

QoS

byte N+1

0

0

X

X

X

X

X

X

RAP means Retain as Published.

NL means No Local.

 

Non-normative example

Figure 3.21 shows the SUBSCRIBE Payload example with two Topic Filters. The first is “a/b” with QoS 1, and the second is “c/d” with QoS 2.

 

Figure 3‑21 - Payload byte format non-normative example

 

Description

7

6

5

4

3

2

1

0

Topic Filter

byte 1

Length MSB (0)

0

0

0

0

0

0

0

0

byte 2

Length LSB (3)

0

0

0

0

0

0

1

1

byte 3

‘a’ (0x61)

0

1

1

0

0

0

0

1

byte 4

‘/’ (0x2F)

0

0

1

0

1

1

1

1

byte 5

‘b’ (0x62)

0

1

1

0

0

0

1

0

Subscription Options

byte 6

Subscription Options (1)

0

0

0

0

0

0

0

1

Topic Filter

byte 7

Length MSB (0)

0

0

0

0

0

0

0

0

byte 8

Length LSB (3)

0

0

0

0

0

0

1

1

byte 9

‘c’ (0x63)

0

1

1

0

0

0

1

1

byte 10

‘/’ (0x2F)

0

0

1

0

1

1

1

1

byte 11

‘d’ (0x64)

0

1

1

0

0

1

0

0

Subscription Options

byte 12

Subscription Options (2)

0

0

0

0

0

0

1

0

3.8.4 SUBSCRIBE Actions

When the Server receives a SUBSCRIBE packet from a Client, the Server MUST respond with a SUBACK packet [MQTT-3.8.4-1]. The SUBACK packet MUST have the same Packet Identifier as the SUBSCRIBE packet that it is acknowledging[MQTT-3.8.4-2].

The Server is permitted to start sending PUBLISH packets matching the Subscription before the Server sends the SUBACK packet.

If a Server receives a SUBSCRIBE packet containing a Topic Filter that is identical to a Non‑shared Subscription’s Topic Filter for the current Session, then it MUST replace that existing Subscription with a new Subscription[MQTT-3.8.4-3]. The Topic Filter in the new Subscription will be identical to that in the previous Subscription, although its Subscription Options could be different. If the Retain Handling option is 0, any existing retained messages matching the Topic Filter MUST be re-sent, but Applicaton Messages MUST NOT be lost due to replacing the Subscription[MQTT-3.8.4-4].

If a Server receives a Non‑shared Topic Filter that is not identical to any Topic Filter for the current Session, a new Non-shared Subscription is created. If the Retain Handling option is not 2, all matching retained messages are sent to the Client.

If a Server receives a Topic Filter that is identical to the Topic Filter for a Shared Subscription that already exists on the Server, the Session is added as a subscriber to that Shared Subscription. No retained messages are sent.

If a Server receives a Shared Subscription Topic Filter that is not identical to any existing Shared Subscription’s Topic Filter, a new Shared Subscription is created. The Session is added as a subscriber to that Shared Subscription. No retained messages are sent.

 

Refer to section 4.8 for more details on Shared Subscriptions.

 

If a Server receives a SUBSCRIBE packet that contains multiple Topic Filters it MUST handle that packet as if it had received a sequence of multiple SUBSCRIBE packets, except that it combines their responses into a single SUBACK response[MQTT-3.8.4-5].

 

The SUBACK packet sent by the Server to the Client MUST contain a Reason Code for each Topic Filter/Subscription Option pair[MQTT-3.8.4-6]. This Reason Code MUST either show the maximum QoS that was granted for that Subscription or indicate that the subscription failed[MQTT-3.8.4-7]. The Server might grant a lower Maximum QoS than the subscriber requested. The QoS of Application Messages sent in response to a Subscription MUST be the minimum of the QoS of the originally published message and the Maximum QoS granted by the Server [MQTT-3.8.4-8]. The server is permitted to send duplicate copies of a message to a subscriber in the case where the original message was published with QoS 1 and the maximum QoS granted was QoS 0.

 

Non-normative comment

If a subscribing Client has been granted maximum QoS 1 for a particular Topic Filter, then a QoS 0 Application Message matching the filter is delivered to the Client at QoS 0. This means that at most one copy of the message is received by the Client. On the other hand, a QoS 2 Message published to the same topic is downgraded by the Server to QoS 1 for delivery to the Client, so that Client might receive duplicate copies of the Message.

 

Non-normative comment

If the subscribing Client has been granted maximum QoS 0, then an Application Message originally published as QoS 2 might get lost on the hop to the Client, but the Server should never send a duplicate of that Message. A QoS 1 Message published to the same topic might either get lost or duplicated on its transmission to that Client.

 

Non-normative comment

Subscribing to a Topic Filter at QoS 2 is equivalent to saying "I would like to receive Messages matching this filter at the QoS with which they were published". This means a publisher is responsible for determining the maximum QoS a Message can be delivered at, but a subscriber is able to require that the Server downgrades the QoS to one more suitable for its usage.

 

The Subscription Identifiers are part of the Session State in the Server and are returned to the Client receiving a matching PUBLISH packet. They are removed from the Server’s Session State when the Server receives an UNSUBSCRIBE packet, when the Server receives a SUBSCRIBE packet from the Client for the same Topic Filter but with a different Subscription Identifier or with no Subscription Identifier, or when the Server sends Session Present 0 in a CONNACK packet.

 

The Subscription Identifiers do not form part of the Client’s Session State in the Client. In a useful implementation, a Client will associate the Subscription Identifiers with other Client side state, this state is typically removed when the Client unsubscribes, when the Client subscribes for the same Topic Filter with a different identifier or no identifier, or when the Client receives Session Present 0 in a CONNACK packet.

 

The Server need not use the same set of Subscription Identifiers in the retransmitted PUBLISH packet. The Client can remake a Subscription by sending a SUBSCRIBE packet containing a Topic Filter that is identical to the Topic Filter of an existing Subscription in the current Session. If the Client remade a subscription after the initial transmission of a PUBLISH packet and used a different Subscription Identifier, then the Server is allowed to use the identifiers from the first transmission in any retransmission. Alternatively, the Server is allowed to use the new identifiers during a retransmission. The Server is not allowed to revert to the old identifier after it has sent a PUBLISH packet containing the new one.

 

Non-normative comment

Usage scenarios, for illustration of Subscription Identifiers.

  • The Client implementation indicates via its programming interface that a publication matched more than one subscription. The Client implementation generates a new identifier each time a subscription is made. If the returned publication carries more than one Subscription Identifier, then the publication matched more than one subscription.

  • The Client implementation allows the subscriber to direct messages to a callback associated with the subscription. The Client implementation generates an identifier which uniquely maps the identifier to the callback. When a publication is received it uses the Subscription Identifier to determine which callback is driven.

  • The Client implementation returns the topic string used to make the subscription to the application when it delivers the published message. To achieve this the Client generates an identifier which uniquely identifies the Topic Filter. When a publication is received the Client implementation uses the identifiers to look up the original Topic Filters and return them to the Client application.

  • A gateway forwards publications received from a Server to Clients that have made subscriptions to the gateway. The gateway implementation maintains a map of each unique Topic Filter it receives to the set of ClientID, Subscription Identifier pairs that it also received. It generates a unique identifier for each Topic Filter that it forwards to the Server. When a publication is received, the gateway uses the Subscription Identifiers it received from the Server to look up the Client Identifier, Subscription Identifier pairs associated with them. It adds these to the PUBLISH packets it sends to the Clients. If the upstream Server sent multiple PUBLISH packets because the message matched multiple subscriptions, then this behavior is mirrored to the Clients.

3.9 SUBACK – Subscribe acknowledgement

A SUBACK packet is sent by the Server to the Client to confirm receipt and processing of a SUBSCRIBE packet.

 

A SUBACK packet contains a list of Reason Codes, that specify the maximum QoS level that was granted or the error which was found for each Subscription that was requested by the SUBSCRIBE.

3.9.1 SUBACK Fixed Header

Figure 3‑22 - SUBACK Packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (9)

Reserved

 

1

0

0

1

0

0

0

0

byte 2

Remaining Length

 

Remaining Length field

This is the length of Variable Header plus the length of the Payload, encoded as a Variable Byte Integer.

3.9.2 SUBACK Variable Header

The Variable Header of the SUBACK Packet contains the following fields in the order: the Packet Identifier from the SUBSCRIBE Packet that is being acknowledged, and Properties.

3.9.2.1 SUBACK Properties

3.9.2.1.1 Property Length

The length of Properties in the SUBACK packet Variable Header encoded as a Variable Byte Integer

3.9.2.1.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is a human readable string designed for diagnostics and SHOULD NOT be parsed by the Client.

 

The Server uses this value to give additional information to the Client. The Server MUST NOT send this Property if it would increase the size of the SUBACK packet beyond the Maximum Packet Size specified by the Client[MQTT-3.9.2-1]. It is a Protocol Error to include the Reason String more than once.

3.9.2.1.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information. The Server MUST NOT send this property if it would increase the size of the SUBACK packet beyond the Maximum Packet Size specified by Client[MQTT-3.9.2-2]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

Figure 3‑23 SUBACK packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

3.9.3 SUBACK Payload

The Payload contains a list of Reason Codes. Each Reason Code corresponds to a Topic Filter in the SUBSCRIBE packet being acknowledged. The order of Reason Codes in the SUBACK packet MUST match the order of Topic Filters in the SUBSCRIBE packet[MQTT-3.9.3-1].

 

Table 3‑8 - Subscribe Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Granted QoS 0

The subscription is accepted and the maximum QoS sent will be QoS 0. This might be a lower QoS than was requested.

1

0x01

Granted QoS 1

The subscription is accepted and the maximum QoS sent will be QoS 1. This might be a lower QoS than was requested.

2

0x02

Granted QoS 2

The subscription is accepted and any received QoS will be sent to this subscription.

128

0x80

Unspecified error

The subscription is not accepted and the Server either does not wish to reveal the reason or none of the other Reason Codes apply.

131

0x83

Implementation specific error

The SUBSCRIBE is valid but the Server does not accept it.

135

0x87

Not authorized

The Client is not authorized to make this subscription.

143

0x8F

Topic Filter invalid

The Topic Filter is correctly formed but is not allowed for this Client.

145

0x91

Packet Identifier in use

The specified Packet Identifier is already in use.

151

0x97

Quota exceeded

An implementation or administrative imposed limit has been exceeded.

158

0x9E

Shared Subscriptions not supported

The Server does not support Shared Subscriptions for this Client.

161

0xA1

Subscription Identifiers not supported

The Server does not support Subscription Identifiers; the subscription is not accepted.

162

0xA2

Wildcard Subscriptions not supported

The Server does not support Wildcard Subscriptions; the subscription is not accepted.

The Server sending a SUBACK packet MUST use one of the Subscribe Reason Codes for each Topic Filter received[MQTT-3.9.3-2].

 

Non-normative comment

There is always one Reason Code for each Topic Filter in the corresponding SUBSCRIBE packet. If the Reason Code is not specific to a Topic Filters (such as 0x91 (Packet Identifier in use)) it is set for each Topic Filter.

 

Solace Implementation Note

The Solace server grants a Maximum QoS of 1 when a client requests a QoS 2 subscription.  The Solace server never returns a QoS 2 in a SUBACK packet.

3.10 UNSUBSCRIBE – Unsubscribe request

An UNSUBSCRIBE packet is sent by the Client to the Server, to unsubscribe from topics.

3.10.1 UNSUBSCRIBE Fixed Header

Figure 3.28 – UNSUBSCRIBE packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (10)

Reserved

 

1

0

1

0

0

0

1

0

byte 2

Remaining Length

 

Bits 3,2,1 and 0 of the Fixed Header of the UNSUBSCRIBE packet are reserved and MUST be set to 0,0,1 and 0 respectively. The Server MUST treat any other value as malformed and close the Network Connection[MQTT-3.10.1-1].

 

Remaining Length field

This is the length of Variable Header (2 bytes) plus the length of the Payload, encoded as a Variable Byte Integer.

3.10.2 UNSUBSCRIBE Variable Header

The Variable Header of the UNSUBSCRIBE Packet contains the following fields in the order: Packet Identifier, and Properties. Section 2.2.1 provides more information about Packet Identifiers. The rules for encoding Properties are described in section 2.2.2.

3.10.2.1 UNSUBSCRIBE Properties

3.10.2.1.1 Property Length

The length of Properties in the UNSUBSCRIBE packet Variable Header encoded as a Variable Byte Integer.

3.10.2.1.2 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by a UTF-8 String Pair.

The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

 

Non-normative comment

User Properties on the UNSUBSCRIBE packet can be used to send subscription related properties from the Client to the Server. The meaning of these properties is not defined by this specification.

3.10.3 UNSUBSCRIBE Payload

The Payload for the UNSUBSCRIBE packet contains the list of Topic Filters that the Client wishes to unsubscribe from. The Topic Filters in an UNSUBSCRIBE packet MUST be UTF-8 Encoded Strings[MQTT-3.10.3-1] as defined in section 1.5.4, packed contiguously.

 

The Payload of an UNSUBSCRIBE packet MUST contain at least one Topic Filter[MQTT-3.10.3-2]. An UNSUBSCRIBE packet with no Payload is a Protocol Error. Refer to section 4.13 for information about handling errors.

 

Solace Implementation Note

  • The Topic Filter must conform to the Solace limitations. Topics outside these bounds will cause the connection to be closed.
  • UNSUBSCRIBE packets can contain at most 1,024 Topic Filters. Exceeding this limit will cause the connection to be closed.

 

Non-normative example

Figure 3.30 shows the Payload for an UNSUBSCRIBE packet with two Topic Filters “a/b” and “c/d”.

 

Figure 3.30 - Payload byte format non-normative example

 

Description

7

6

5

4

3

2

1

0

Topic Filter

byte 1

Length MSB (0)

0

0

0

0

0

0

0

0

byte 2

Length LSB (3)

0

0

0

0

0

0

1

1

byte 3

‘a’ (0x61)

0

1

1

0

0

0

0

1

byte 4

‘/’ (0x2F)

0

0

1

0

1

1

1

1

byte 5

‘b’ (0x62)

0

1

1

0

0

0

1

0

Topic Filter

byte 6

Length MSB (0)

0

0

0

0

0

0

0

0

byte 7

Length LSB (3)

0

0

0

0

0

0

1

1

byte 8

‘c’ (0x63)

0

1

1

0

0

0

1

1

byte 9

‘/’ (0x2F)

0

0

1

0

1

1

1

1

byte 10

‘d’ (0x64)

0

1

1

0

0

1

0

0

3.10.4 UNSUBSCRIBE Actions

The Topic Filters (whether they contain wildcards or not) supplied in an UNSUBSCRIBE packet MUST be compared character-by-character with the current set of Topic Filters held by the Server for the Client. If any filter matches exactly then its owning Subscription MUST be deleted[MQTT-3.10.4-1], otherwise no additional processing occurs.

 

When a Server receives UNSUBSCRIBE :

  • It MUST stop adding any new messages which match the Topic Filters, for delivery to the Client [MQTT-3.10.4-2].
  • It MUST complete the delivery of any QoS 1 or QoS 2 messages which match the Topic Filters and it has started to send to the Client[MQTT-3.10.4-3].
  • It MAY continue to deliver any existing messages buffered for delivery to the Client.

 

The Server MUST respond to an UNSUBSCRIBE request by sending an UNSUBACK packet[MQTT-3.10.4-4]. The UNSUBACK packet MUST have the same Packet Identifier as the UNSUBSCRIBE packet. Even where no Topic Subscriptions are deleted, the Server MUST respond with an UNSUBACK[MQTT-3.10.4-5].

 

If a Server receives an UNSUBSCRIBE packet that contains multiple Topic Filters, it MUST process that packet as if it had received a sequence of multiple UNSUBSCRIBE packets, except that it sends just one UNSUBACK response[MQTT-3.10.4-6].

 

If a Topic Filter represents a Shared Subscription, this Session is detached from the Shared Subscription.  If this Session was the only Session that the Shared Subscription was associated with, the Shared Subscription is deleted. Refer to section 4.8.2 for a description of Shared Subscription handling.

3.11 UNSUBACK – Unsubscribe acknowledgement

The UNSUBACK packet is sent by the Server to the Client to confirm receipt of an UNSUBSCRIBE packet.

3.11.1 UNSUBACK Fixed Header

Figure 3.31 – UNSUBACK packet Fixed Header

Bit

7

6

5

4

3

2

1

0

byte 1

MQTT Control Packet type (11)

Reserved

 

1

0

1

1

0

0

0

0

byte 2

Remaining Length

 

Remaining Length field

This is the length of the Variable Header plus the length of the Payload, encoded as a Variable Byte Integer.

3.11.2 UNSUBACK Variable Header

The Variable Header of the UNSUBACK Packet the following fields in the order: the Packet Identifier from the UNSUBSCRIBE Packet that is being acknowledged, and Properties. The rules for encoding Properties are described in section 2.2.2.

 

Figure 3.32 – UNSUBACK packet Variable Header

Bit

7

6

5

4

3

2

1

0

byte 1

Packet Identifier MSB

byte 2

Packet Identifier LSB

3.11.2.1 UNSUBACK Properties

3.11.2.1.1 Property Length

The length of the Properties in the UNSUBACK packet Variable Header encoded as a Variable Byte Integer.

3.11.2.1.2 Reason String

31 (0x1F) Byte, Identifier of the Reason String.

Followed by the UTF-8 Encoded String representing the reason associated with this response. This Reason String is a human readable string designed for diagnostics and SHOULD NOT be parsed by the Client.

 

The Server uses this value to give additional information to the Client. The Server MUST NOT send this Property if it would increase the size of the UNSUBACK packet beyond the Maximum Packet Size specified by the Client[MQTT-3.11.2-1]. It is a Protocol Error to include the Reason String more than once.

3.11.2.1.3 User Property

38 (0x26) Byte, Identifier of the User Property.

Followed by UTF-8 String Pair. This property can be used to provide additional diagnostic or other information. The Server MUST NOT send this property if it would increase the size of the UNSUBACK packet beyond the Maximum Packet Size specified by the Client [MQTT-3.11.2-2]. The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

3.11.3 UNSUBACK Payload

The Payload contains a list of Reason Codes. Each Reason Code corresponds to a Topic Filter in the UNSUBSCRIBE packet being acknowledged. The order of Reason Codes in the UNSUBACK packet MUST match the order of Topic Filters in the UNSUBSCRIBE packet [MQTT-3.11.3-1].

 

The values for the one byte unsigned Unsubscribe Reason Codes are shown below. The Server sending an UNSUBACK packet MUST use one of the Unsubscribe Reason Code values for each Topic Filter received[MQTT-3.11.3-2].

 

Table 3‑9 - Unsubscribe Reason Codes

Value

Hex

Reason Code name

Description

0

0x00

Success

The subscription is deleted.

17

0x11

No subscription existed

No matching Topic Filter is being used by the Client.

128

0x80

Unspecified error

The unsubscribe could not be completed and the Server either does not wish to reveal the reason or none of the other Reason Codes apply.

131

0x83

Implementation specific error