Schema

Protocol Buffer

In Tansu a Protobuf schema defines the key and/or value of each message on a particular topic. The schema is named after the topic with a proto file extension.

In etc/schema/search.proto:

syntax = 'proto3';

enum Corpus {
  CORPUS_UNSPECIFIED = 0;
  CORPUS_UNIVERSAL = 1;
  CORPUS_WEB = 2;
  CORPUS_IMAGES = 3;
  CORPUS_LOCAL = 4;
  CORPUS_NEWS = 5;
  CORPUS_PRODUCTS = 6;
  CORPUS_VIDEO = 7;
}

message Value {
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
  Corpus corpus = 4;
}

The above Protocol Buffer schema defines the properties of the value of the message. The broker will validate any message that is produced to the search topic, rejecting any that do not conform with an INVALID_RECORD error.

Example

Create the search topic if not already present:

tansu topic create search

Produce a message to the search topic. The JSON will be encoded in a Protocol Buffer message by the cat subcommand:

echo '{"value": {"query": "abc/def", "page_number": 6, "results_per_page": 13, "corpus": "CORPUS_WEB"}}' | tansu cat produce search

Consume messages from the search topic:

tansu cat consume search

Messages are automatically converted back into a JSON format by the cat subcommand:

[{
   "key":null,
   "value":{
     "corpus":"CORPUS_WEB",
     "pageNumber":6,
     "query":"abc/def",
     "resultsPerPage":13
   }
}]
Previous
JSON
Next
broker