Validation

Validators ensure that the MQTT messages on your broker fulfill your requirements.

In schema validators, requirements are specified in schemas that ensure the format of the MQTT message payload.
Validation can include checking for the existence of fields or setting limits for values in the payload.

Validation in Data Policies

Since MQTT is data agnostic, MQTT clients can publish data to downstream services through the broker regardless of whether the data is valid or not.
In practice, invalid or incorrectly formatted data can cause unpredictable behavior. For example, in a microservice that needs to process sensor data.

The validations section of your HiveMQ Data Hub policy ensures that the MQTT data in your broker is valid, reliable, consistent, and conforms to your predefined standards.

The validations in your policy definition determine how incoming messages are evaluated. Currently, HiveMQ Data Hub data validation supports validators of the type schema only.

  • The array of validators in the validations section lists the validators the policy executes for all incoming MQTT messages.

Each validator can have one of two outcomes:

  • success: All validators evaluate to true.

  • failure: Any validator evaluates to false.

Schema-based Validation in Data Policies

Schema-based data validation is an effective way to enhance the value of your data pipelines.
Validation against appropriately configured schemas can ensure data quality, reduce errors, and improve the overall usability and interoperability of your data.

The HiveMQ Data Hub supports JSON Schema and Protobuf schema validation for your data policies.

To set up schema-based validation in your data policy, set the validator type to schema and define the arguments that you want to use.

  • schemas: Lists an array of one or more schemas that are used for the validation.

    • schemaId: The unique string that references the schema in the HiveMQ Data Hub.

    • version: The version number of the schema to specify a certain version or the latest schema by using "latest".

  • strategy: Defines how the success or failure of the validator is evaluated. Possible entries are ALL-OF and ANY_OF.

    • ALL_OF: Specifies that the validation is only considered successful (success) if all listed schemas are valid, otherwise unsuccessful (failure).

    • ANY_OF: Specifies that the validation is considered successful (success) if any one of the listed schemas is valid, otherwise unsuccessful (failure).

Example minimal validation configuration in a data policy
"validation": {
  "validators": [
    {
      "type": "schema",
      "arguments": {
        "strategy": "ALL_OF",
        "schemas": [
          {
            "schemaId": "gps_coordinates",
            "version": "1"
          }
        ]
      }
    }
  ]
}
To learn more about data validation feature, see our Getting Started with MQTT Data Validation Using HiveMQ Data Hub blog post.