ltm rule command MQTT packet id
iRule(1) BIG-IP TMSH Manual iRule(1)
MQTT::packet_id
Get or set packet-id of MQTT message
SYNOPSIS
MQTT::packet_id (PACKETID)?
DESCRIPTION
This command can be used to get or set packet-id field of MQTT message. This command is valid only for
following MQTT message types:
PUBLISH (if QoS > 0)
PUBACK
PUBREC
PUBREL
PUBCOMP
SUBSCRIBE
SUBACK
UNSUBSCRIBE
UNSUBACK
PINGREQ
PINGRESP
DISCONNECT
Syntax
MQTT::packet_id []
MQTT::packet_id
* Returns the packet-id of the MQTT message.
MQTT::packet_id
* Replaces the packet-id of the MQTT message with . The value supplied must be less than
65536.
RETURN VALUE
When called without an argument, this command returns the packet-id of MQTT message
VALID DURING
MQTT_CLIENT_INGRESS MQTT_SERVER_INGRESS MQTT_CLIENT_DATA MQTT_SERVER_DATA MQTT_CLIENT_EGRESS
MQTT_SERVER_EGRESS
EXAMPLES
#Example: Split SUBSCRIBE with multiple topics into separate SUBSCRIBE messages
when MQTT_CLIENT_INGRESS {
set type [MQTT::type]
switch $type {
"SUBSCRIBE" {
set count [MQTT::topic count]
if { $count > 1 } {
set topiclist [MQTT::topic list]
set qoslist [list]
foreach topic $topiclist {
lappend qoslist [MQTT::topic qos $topic]
}
set packetid [MQTT::packet_id]
set i 0
foreach topic $topiclist {
if { $i == 0 } {
MQTT::replace type SUBSCRIBE packet_id $packetid topic_list $topic [lindex $qoslist $i]
table add -subtable "outstanding_packetid_table" "[client_addr]_[client_port]_${packetid}" $count
} else {
MQTT::insert after type SUBSCRIBE packet_id [expr { ($packetid + 1000 + $i)%65535}] topic_list $topic [lindex $qoslist $i]
}
set i [expr { $i + 1 }]
}
}
}
}
}
when SERVER_CONNECTED {
set suback_count 0
set rclist [list]
}
when MQTT_SERVER_INGRESS {
set type [MQTT::type]
switch $type {
"SUBACK" {
set packetid [MQTT::packet_id]
if { $suback_count == 0 } {
set count [table lookup -subtable "outstanding_packetid_table" "[client_addr]_[client_port]_${packetid}"]
if { $count != "" } {
set suback_count $count
} elseif { [llength $rclist] > 0 } {
MQTT::replace type SUBACK return_code_list $rclist
set rclist [list]
}
}
if { $suback_count > 0 } {
set suback_count [expr { $suback_count - 1}]
lappend rclist [MQTT::return_code_list]
MQTT::drop
}
}
}
}
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-13.0.0 --First introduced the command.
BIG-IP 2020-06-23 iRule(1)