UNSUBSCRIBE

Unsubscribe from named Topics

The UNSUBSCRIBE message allows a client to tell the broker that it is no longer interested in receiving messages on specified topics.
 

Fixed Header

See the Fixed Header section for more information,
 
bit
7
6
5
4
3
2
1
0
byte 1 
Message Type (10)
DUP flag
QoS level
RETAIN
 
1
0
1
0
0
 0
x
byte 2 
Remaining Length

This example shows the first transmission (DUP flag clear).
 

QoS level

UNSUBSCRIBE messages use a QoS of 1, to allow the acknowledgement of multiple unsubscribe requests to be managed. The corresponding UNSUBACK can be identified by matching the Message ID. This also allows the handling of retries on UNSUBSCRIBE messages to be handled in exactly the same way as a PUBLISH message.
 

DUP flag

The DUP bit should be set if this is a message that is being retransmitted after the non-arrival of a UNSUBACK message after some specified timeout. This indicates to the broker that it may be a duplicate of a message already received. If this is the first sending of the message, the DUP bit should be clear.
 

RETAIN flag

The RETAIN flag is not used in the UNSUBSCRIBE message.

Remaining Length

The Remaining Length is the length of the Payload.
This may be a multi-byte field. See the Fixed Header section for more details.
 

Variable Header

The Variable Header portion of the UNSUBSCRIBE message contains the Message Identifier.

Message Identifier

UNSUBSCRIBE is treated as a QoS1 message, and so has a Message ID. See the QoS section for more details. It should be noted that typically the protocol library would take responsibility for generating this identifier, and passing it back to the publishing application, possibly as a return handle. This approach avoids the risk of duplicate Message Identifiers being generated by multiple applications, or multiple publishing threads, running on a single client.

The Message Identifer is a 16 bit unsigned integer, which will typically increase, but is not required to increase
by exactly one from one message to the next.

Message ID 0 (i.e. 0x0000) is reserved as an invalid Message ID, and must not be used.
The ordering of the 2 bytes of the Message Identifier is MSB, then LSB (big-endian).

See the Variable Header section for more information.
 

As an example, if the Message ID is 10, the format of the Variable Header would be:
 
  Description
7
6
5
4
3
2
1
0
Message Identifier
byte 1 Message ID MSB (0)
0
0
0
0
0
0
0
0
byte 2 Message ID LSB (10) 0 0 0 0 1 0 1 0

 
 
 

Payload

The Payload of an UNSUBSCRIBE message contains a list of Topic Names from which the client wishes to unsubscribe. The strings are UTF-encoded, and are packed contiguously, one after the other.

The Topic Names in a UNSUBSCRIBE message will not be compressed in any way.
 

Response

The response from the broker to a client UNSUBSCRIBE message is an UNSUBACK message from the broker.
 


Discussion


BACK to index 


Last Modified: 19-Oct-99