ltm rule command MQTT topic
iRule(1) BIG-IP TMSH Manual iRule(1)
MQTT::topic
Manipulate topic(s) of MQTT message.
SYNOPSIS
MQTT::topic (('replace' TOPIC) |
('count') |
('list') |
('index' INDEX) |
('add' TOPIC ('0' | '1' | '2')?) |
('delete' TOPIC) |
('qos' TOPIC))?
DESCRIPTION
This command can be used to manipulate topic(s) of MQTT message. This command is valid only for following MQTT message
types:
PUBLISH
SUBSCRIBE
UNSUBSCRIBE
Syntax
MQTT::topic [ replace | count | list | index |
add [] | delete ]
MQTT::topic
* Get the topic-name of MQTT PUBLISH message. Or the first topic of a SUBSCRIBE or UNSUBSCRIBE message.
MQTT::topic replace
* Set the topic-name of MQTT PUBLISH message to specified string.
This command is valid only for PUBLISH messages.
MQTT::topic count
* Get the number of topics in MQTT SUBSCRIBE and UNSUBSCRIBE messages.
MQTT::topic list
* Get the list of topics in MQTT SUBSCRIBE and UNSUBSCRIBE messages.
MQTT::topic index
* Get the topics at index in the list of topics in MQTT SUBSCRIBE and UNSUBSCRIBE messages.
MQTT::topic qos
* This command is valid for SUBSCRIBE messages only. It returns the QoS value of the given .
MQTT::topic add []
* For SUBSCRIBE messages, add the specified and to the end of list of topics.
can only be 0,1, or 2. If not specified QoS 0 will be used.
For UNSUBSCRIBE messages, add the specified to the end of list of topics.
UNSUBSCRIBE messages do not need QoS. If supplied, it will be ignored.
MQTT::topic delete
* Delete the specified and its qos from the topics in MQTT SUBSCRIBE and UNSUBSCRIBE messages.
RETURN VALUE
When called without an argument, this command returns the topic-name of MQTT PUBLISH message, or the topic-name of the
first topic of MQTT SUBSCRIBE and UNSUBSCRIBE messages.
VALID DURING
MQTT_CLIENT_INGRESS MQTT_SERVER_INGRESS MQTT_CLIENT_DATA MQTT_SERVER_DATA MQTT_CLIENT_EGRESS MQTT_SERVER_EGRESS
EXAMPLES
#Automatically assign a subscription to the client for topic "$SYS/broker/alerts/critical":
when MQTT_CLIENT_INGRESS {
set cmtype [MQTT::type]
if { $cmtype == "SUBSCRIBE" } {
set topic_count [MQTT::topic count]
set mid [MQTT::packet_id]
table add -subtable "packetid_count_table" "[client_addr]_[client_port]_${mid}" $topic_count
MQTT::topic add "$SYS/broker/alerts/critical" 0
}
}
when MQTT_SERVER_INGRESS {
set smtype [MQTT::type]
if {$smtype == "SUBACK"} {
set mid [MQTT::packet_id]
set tc [table lookup -subtable "packetid_count_table" "[client_addr]_[client_port]_${mid}"]
set return_codes [MQTT::return_code_list]
set return_codes [lreplace $return_codes $tc $tc]
MQTT::replace type SUBACK packet_id $mid return_code_list $return_codes
}
}
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-13.0.0 --First introduced the command.
BIG-IP 2022-04-12 iRule(1)