Schema
AVRO
In Tansu an AVRO schema defines the key and/or value of each message on a topic. The schema is named after the topic with a avsc file extension.
For example, the observation topic is backed by an AVRO schema in etc/schema/observation.avsc:
{
"type": "record",
"name": "observation",
"fields": [
{ "name": "key", "type": "string", "logicalType": "uuid" },
{
"name": "value",
"type": "record",
"fields": [
{ "name": "amount", "type": "double" },
{ "name": "unit", "type": "enum", "symbols": ["CELSIUS", "MILLIBAR"] }
]
}
]
}
The schema defines the properties of the key and value of the message. The broker will validate any message that is produced to the observation topic, rejecting any that do not conform with an INVALID_RECORD error.
Example
Create the observation topic if not already present:
tansu topic create observation
The cat subcommand can be used to produce validated bulk data from a file using etc/data/observations.json. The JSON will be encoded into AVRO by the cat subcommand before being sent to the broker in a produce request:
tansu cat produce observation etc/data/observations.json
Consume messages from observation topic, automatically converted back into a JSON format by the cat subcommand:
tansu cat consume observation
[{"key":"1e44d9c2-5e7a-443b-bf10-2b1e5fd72f15","value":{"amount":23.2,"unit":"CELSIUS"}}]