ltm rule command MQTT qosΒΆ

iRule(1)		      BIG-IP TMSH Manual		      iRule(1)



MQTT::qos
       Get or set qos of MQTT PUBLISH message

SYNOPSIS
       MQTT::qos ('0' | '1' | '2')?

DESCRIPTION
       This command can be used to get or set qos field of MQTT message.  This
       command is valid only for following MQTT message types:

	   PUBLISH

       Syntax

       MQTT::qos [ 0 | 1 | 2 ]

       MQTT::qos
	   * Get the qos field of MQTT PUBLISH message

       MQTT::qos 0
	   * Set the qos of MQTT PUBLISH message to at most once delivery.
	     When QoS is changed to 0 from 1 or 2, the packet-id field
	     of the PUBLISH message will be removed. Call MQTT::packet_id
       before
	     calling MQTT::qos 0 to save original packet-id if needed.

       MQTT::qos 1
	   * Set the qos of MQTT PUBLISH message to at least once delivery.
	     When changing from 0, this call must be followed by
	     MQTT::packet_id  to maintain MQTT protocol
       correctness.
	     This is because packet-id is not present in PUBLISH messages at
       QoS 0,
	     while it is required at levels 1 and 2.

       MQTT::qos 2
	   * Set the qos field of MQTT PUBLISH message to exactly once
       delivery
	     When changing from 0, this call must be followed by
	     MQTT::packet_id  to maintain MQTT protocol
       correctness.
	     This is because packet-id is not present in PUBLISH messages at
       QoS 0,
	     while it is required at levels 1 and 2.

RETURN VALUE
       When called without an argument, this command returns the qos of MQTT
       message

VALID DURING
       MQTT_CLIENT_INGRESS MQTT_SERVER_INGRESS MQTT_CLIENT_DATA
       MQTT_SERVER_DATA

EXAMPLES
	Downgrading QoS to 0:

	when MQTT_CLIENT_INGRESS {
	    set mtype [MQTT::type]
	    if {$mtype == "PUBLISH"} {
		set in_qos [MQTT::qos]
		if { $in_qos > 0 } {
		    set pktid [MQTT::packet_id]
		}
		MQTT::qos 0
		if { $in_qos == 1 } {
		    MQTT::respond type PUBACK packet_id $pktid
		} elseif { $in_qos == 2 } {
		    MQTT::respond type PUBREC packet_id $pktid
		}
	    } elseif {$mtype == "PUBREL"} {
		set pktid [MQTT::packet_id]
		MQTT::drop
		MQTT::respond type PUBCOMP packet_id $pktid
	    }
	}

	Changing QoS to 1:

	when CLIENT_ACCEPTED {
	   set self_pktid 1
	}
	when MQTT_CLIENT_INGRESS {
	    set cmtype [MQTT::type]
	    if {$cmtype == "PUBLISH"} {
		set in_qos [MQTT::qos]
		MQTT::qos 1
		if { $in_qos == 0 } {
		    MQTT::packet_id $self_pktid
		    set self_pktid [$self_pktid + 1]
		}
	    } elseif {$cmtype == "PUBREL"} {
		set pktid [MQTT::packet_id]
		MQTT::drop
		MQTT::respond type PUBCOMP packet_id $pktid
	    }
	}

	when MQTT_SERVER_INGRESS {
	    set smtype [MQTT::type]
	    if {$smtype == "PUBACK"} {
	       if {$in_qos == 0} {
		   MQTT::drop
	       } elseif {$in_qos == 2} {
		   set pktid [MQTT::packet_id]
		   MQTT::replace type PUBREC packet_id $pktid
	       }
	    }
	}

HINTS
SEE ALSO
CHANGE LOG
       @BIGIP-13.0.0 --First introduced the command.



BIG-IP				  2017-01-31			      iRule(1)