Skip to main content

Message Validation

The Spotflow IoT Platform allows you to validate the payload of messages sent by your devices before they are persisted in storage. The message validation is configured at the stream level via Portal, CLI, or API.

There are two modes you can choose from:

  1. Discard - the message is discarded if it does not pass validation. Specifically, the message will not be persisted in storage and a Messages Completion Event will not be sent to connected egress sinks.
  2. Dry Run - the message is processed as usual; it is not discarded regardless of the validation outcome. The message validation result is stored in the message blob metadata under the isValid key.

Configuration

Message validation is configured using JSON Schema. The schema is a JSON object that defines the structure of the message payload.

It is recommended to always specify which draft of the JSON Schema standard the schema adheres to. Supported versions:

  • 2020-12 (default schema if not specified)
  • 2019-09
  • Draft 7
  • Draft 6

For example, consider the following JSON Schema:

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"temperature": {
"type": "number",
"minimum": -50,
"maximum": 50
},
"humidity": {
"type": "number",
"minimum": 0,
"maximum": 100
}
},
"required": ["temperature", "humidity"]
}

A message with the payload {"temperature": 25, "humidity": 60} will be considered valid, while a message with the payload {"temperature": 25} will be considered invalid because the humidity property is missing.

You can also reference a schema hosted at a specific URL. This reference will be resolved at the time of configuration. Only the HTTPS protocol is supported.

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
{ "$ref": "https://your-company-dotcom/example" },
{ "type": "number", "minimum": 0 }
]
}

Limitations

  1. The message payload cannot be larger than 1MB after decompression.
  2. Chunked messages are not supported.

In either of these cases, the message is considered invalid, and the subsequent action depends on the mode you have chosen.