mqttPayloadType

The "mqttPayloadType" property specifies the expected data type of the MQTT payload. It defines the expected data type of message payloads sent to a topic. It controls how the MQTT broker stores and validates the MQTT payload. 

It also determines how the payload is delivered to JavaScript transform steps. For example, if "mqttPayloadType" is set to "json", an MQTT message containing a JSON payload is delivered to transform steps as a JavaScript object; otherwise, it is delivered as a variant object.

This property is useful because the FairCom server allows you to configure each topic to receive a specific data type in MQTT payloads. Different topics may expect different types of payloads. For example, one topic may expect to receive JSON,the  and another may expect images. The server can validate the expected type and log errors in the error and log fields, which allows users, applications, and JavaScript transform steps to identify and troubleshoot invalid MQTT messages.

When the server receives an MQTT message, it takes the binary value from the MQTT payload and stores it in the source_payload field. The source_payload field is a variant, which means it stores the value along with its data type. If there are no errors in validating the MQTT payload to match the type specified in "mqttPayloadType", the server assigns the value of "mqttPayloadType" as the variant field's type. 

If "validateMqttPayload" is true, the server validates the MQTT payload to ensure it matches the type specified by "mqttPayloadType". The server may also convert the MQTT payload into another form before storing it. If the MQTT payload does not match the expected type or cannot be converted, the server stores the payload in the source_payload field, sets its variant type to "binary", and sets the error field to 1 to indicate an error. It also adds an error entry to the JSON array in the log field. 

  • This property is a hint to the server about the format and type of the MQTT message payload.
  • This property does not cause the server to validate the MQTT payload to see if it matches the type you set. The server stores the payload as is without validation. For example, setting the type to "json" does not stop the server from receiving and storing a non-JSON value or an invalid JSON document in the source payload.
  • The FairCom Edge Explorer application may use the value of this property to determine the default way to display a topic's payload.
  • The transform engine may use the value of this property to help it transform the source payload.

FairCom's MQTT server does the following when a topic receives an MQTT message and "mqttPayloadType" is set to one of the following values:

  • "binary" - The server stores the MQTT payload in the source_payload field with no validation or conversion and assigns the "binary" type to the source_payload field. It ignores the value of "validateMqttPayload".
  • "json" - The server stores the MQTT payload in the source_payload field.
    • If "validateMqttPayload" is true, it validates the MQTT payload as JSON.
      • If successful, it assigns the "json" type to the source_payload field.
      • If unsuccessful, the server assigns a "binary" type to the source_payload field and sets the error field to 1 to indicate there is an error. It also adds an error entry to the JSON array in the log field.
    • If "validateMqttPayload" is false, it does not validate the MQTT payload and assigns the "json" type to the source_payload field. 
      • The publisher must send MQTT messages containing valid JSON, or database queries may return errors.
  • "utf8" - The server stores the MQTT payload in the source_payload field.
    • If "validateMqttPayload" is true, it validates the MQTT payload as a UTF-8 string.
      • If successful, it assigns the "string" type to the source_payload field.
      • If unsuccessful, the server assigns a "binary" type to the field and sets the error field to 1 to indicate there is an error. It also adds an error object to the JSON array in the log field.
    • If "validateMqttPayload" is false, it does not validate the MQTT payload and assigns the "utf8" type to the source_payload field.
      • The publisher must send MQTT messages containing valid UTF-8, or database queries and transform steps may return errors.
  • "variantObject" - The server validates the payload as a variant object.
    • If successful, the server extracts the value from the variant object’s "value" property and assigns it to the value of the source_payload field. It also assigns the variant object’s type to the type of the source_payload field.
    • If unsuccessful, the server writes the MQTT payload to the source_payload field, assigns a "binary" type to the field, and sets the error field to 1, to indicate that it also adds an error object to the JSON array in the log field.
    • The server always validates a “variantObject”, and thus ignores the value of “validateMqttPayload”
  • "siemensUdt" - The server stores the MQTT payload in the source_payload field without validation or conversion and assigns the "binary" type to the source_payload field. It ignores the value of "validateMqttPayload".
  • "jpeg" - The server stores the MQTT payload in the source_payload field without validation or conversion and assigns the "binary" type to the source_payload field. It ignores the value of "validateMqttPayload".
  • "xml" - The server stores the MQTT payload in the source_payload field without validation or conversion and assigns the "binary" type to the source_payload field. It ignores the value of "validateMqttPayload".