MQTT Support for Rewrite
Rewrite action for MQTT
add rewrite action <name> <rewrite_type> <target> <rewrite_action>
Rewrite type for MQTT
-
replace_mqtt -
insert_before_mqtt -
insert_after_mqtt -
delete_mqtt -
insert_mqtt
Rewrite target for MQTT
-
Rewrite a client ID in the connect packet using the
replace_mqttaction type.add rewrite action rwact1 replace_mqtt MQTT.CONNECT.CLIENTID "\"xyz\"" -
Rewrite a topic in the publish request using the
replace_mqttaction type.add rewrite action rwact1 replace_mqtt MQTT.PUBLISH.TOPIC "\"testing/test123\"" -
Rewrite to insert a property using the insert_mqtt action type.
add rewrite action rwact1 insert_mqtt MQTT.NEW_PROPERTY("prop1", "test") -
Delete a topic using the delete_mqtt action type.
add rewrite action rwact2 delete_mqtt MQTT.SUBSCRIBE.TOPIC_FILTERS.TOPIC(1)
Rewrite action for MQTT
-
MQTT.NEW_KEEPALIVE(interval) -
MQTT.NEW_PACKET_IDENTIFIER(packetID) -
MQTT.NEW_REASON_CODE(retCode) -
MQTT.NEW_PUBLISH(topic_name, payload) -
MQTT.NEW_CONNECT_USERNAME(username) -
MQTT.NEW_CONNECT_WILL_MESSAGE(will_topic, will_payload, will_Qos, will_retain) -
MQTT.NEW_TOPIC(topic, qos) -
MQTT.NEW_TOPIC(topic) -
MQTT.NEW_PROPERTY(key, value)
add rewrite action rwact1 replace_mqtt MQTT.CONNECT.KEEPALIVE MQTT.NEW_KEEPALIVE(90)
add rewrite action rwact1 replace_mqtt MQTT.CONNECT.USERNAME "\"user1\""
Rewrite policy for MQTT
add rewrite policy <name> <rewrite_rule> <rewrite_action>
add rewrite action insert_mqtt_username insert_mqtt MQTT.NEW_CONNECT_USERNAME("user1")
add rewrite policy rewrite_mqtt_username "MQTT.COMMAND.EQ(CONNECT) && MQTT.CONNECT.USERNAME.LENGTH.EQUALS(0) insert_mqtt_username
Bind points for MQTT
-
MQTT_REQ_DEFAULT -
MQTT_REQ_OVERRIDE -
MQTT_RES_DEFAULT -
MQTT_RES_OVERRIDE
-
bind rewrite global <policyName> <priority> [-type MQTT_REQ_OVERRIDE | MQTT_REQ_DEFAULT | MQTT_RES_OVERRIDE | MQTT_RES_DEFAULT] -
bind lb|cs vserver <virtualServerName> -policyName <policyName> -priority <positiveInteger> -type REQUEST|RESPONSE
-
bind rewrite global pol1 10 -type MQTT_REQ_DEFAULT -
add/bind lb vserver v1 -policyName pol1 -type reqUEST -priority 10
Configure a rewrite policy for MQTT
-
Enable the rewrite feature on the NetScaler appliance.
enable ns feature REWRITE -
Add a rewrite action.
add rewrite action rwact1 replace_mqtt MQTT.CONNECT.KEEPALIVE MQTT.NEW_KEEPALIVE(10) -
Add a rewrite policy.
add rewrite policy pol1 MQTT.COMMAND.EQ(CONNECT) rwact1 -
Configure an MQTT load balancing virtual server.
add lb vserver v1 MQTT 1.1.1.1 1883 -
Bind the rewrite policy globally, or to a specific load balancing virtual server.
bind rewrite global pol1 10 -type MQTT_REQ_DEFAULTadd/bind lb vserver v1 -policyName pol1 -type REQUEST -priority 10
Use case 1: Replace the user name in the MQTT CONNECT message with the certificate name
MQTT CONNECT message, which contains the user name as "admin". This user name must be replaced with the serial number (16 digit) that is extracted from the client certificate (cert name).
-
A Transport Control Protocol (TCP) request is sent to the load balancer.
-
In the load balancer, the user name is replaced with the certificate name.
-
The request is forwarded to the MQTT broker.
-
This new user name is used for authorization through the webhook payload.
add rewrite action mqtt_rw_unameact1 replace_mqtt MQTT.CONNECT.USERNAME CLIENT.SSL.CLIENT_CERT.SERIALNUMBER
add rewrite policy mqtt_rw_uname_pol1 "MQTT.COMMAND.EQ(CONNECT)" mqtt_rw_unameact1
bind cs vserver mqtt_frontend_cs -policyName mqtt_rw_uname_pol1 -priority 10 -gotoPriorityExpression END -type REQUEST
Use case 2: Provide subscription to a new TOPIC
-
add rewrite action act2 insert_before_mqtt MQTT.TOPIC_FILTERS.TOPIC(1) MQTT.NEW_TOPIC(topic2, 2) -
add rewrite policy policy2 “MQTT.COMMAND.EQ(SUBSCRIBE) && MQTT.SUBSCRIBE. TOPIC_FILTERS.TOPIC.CONTAINS(\"test\")" act2