Search
⌃K
Links

JSON Schema

JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It provides clear human- and machine-readable documentation and offers data validation which is useful for Automated testing—ensuring the quality of client-submitted data.

Supported Features

  • Versioning
  • Embedded serialization
  • Producer Live evolution
  • Import packages (soon)
  • Import types (soon)

Getting started

Attach a schema

Step 1: Create a new schema

GUI
SDK
Head to the "Schemaverse" page
Create a new schema by clicking on "Create from blank"
Soon.

Step 2: Attach

GUI
SDK
Head to your station, and on the top-left corner, click on "+ Attach schema"
It can be found through the different SDKs docs.

Produce a message (Serialization)

Node.js
Go
Python
TypeScript
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
In node.js, we can simply produce an object. Behind the scenes, the object will be serialized based on the attached schema and data format - protobuf.
Example schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "contact_details",
"type": "object",
"properties": {
"fname": {
"type": "string"
},
"lname": {
"type": "string"
}
}
}
Code:
1
const memphis = require("memphis-dev");
2
3
(async function () {
4
try {
5
await memphis.connect({
6
host: "MEMPHIS_BROKER_URL",
7
username: "APPLICATION_USER",
8
password: "PASSWORD"
9
});
10
const producer = await memphis.producer({
11
stationName: "STATION_NAME",
12
producerName: "PRODUCER_NAME"
13
});
14
var payload = {
15
fname: "Daniel",
16
lname: "Craig",
17
};
18
try {
19
await producer.produce({
20
message: payload
21
});
22
} catch (ex) {
23
console.log(ex.message)
24
}
25
} catch (ex) {
26
console.log(ex);
27
memphis.close();
28
}
29
})();
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "contact_details",
"type": "object",
"properties": {
"fname": {
"type": "string"
},
"lname": {
"type": "string"
}
}
}
Code:
package main
import (
"fmt"
"os"
"github.com/memphisdev/memphis.go"
)
func main() {
conn, err := memphis.Connect("MEMPHIS_BROKER_URL", "APPLICATION_TYPE_USERNAME", memphis.Password("PASSWORD"))
if err != nil {
os.Exit(1)
}
defer conn.Close()
p, err := conn.CreateProducer("STATION_NAME", "PRODUCER_NAME")
hdrs := memphis.Headers{}
hdrs.New()
err = hdrs.Add("key", "value")
if err != nil {
fmt.Printf("Header failed: %v\n", err)
os.Exit(1)
}
msg := make(map[string]interface{})
msg["fname"] = "Daniel"
msg["lname"] = "Craig"
err = p.Produce(msg, memphis.MsgHeaders(hdrs))
if err != nil {
fmt.Printf("Produce failed: %v\n", err)
os.Exit(1)
}
}
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "contact_details",
"type": "object",
"properties": {
"fname": {
"type": "string"
},
"lname": {
"type": "string"
}
}
}
Code:
import asyncio
import json
from memphis import Memphis, Headers, MemphisError, MemphisConnectError, MemphisSchemaError
async def main():
memphis = Memphis()
await memphis.connect(host="MEMPHIS_HOST", username="MEMPHIS_USERNAME", password="PASSWORD")
producer = await memphis.producer(
station_name="STATION_NAME", producer_name="PRODUCER_NAME")
headers = Headers()
headers.add("key", "value")
msg = '{ "fname":"John", "lname":"Mayer"}'
msg = json.loads(msg)
try:
await producer.produce(msg, headers=headers)
except Exception as e:
print(e)
finally:
await asyncio.sleep(3)
await memphis.close()
if __name__ == '__main__':
asyncio.run(main())
Memphis abstracts the need for external serialization functions and embeds them within the SDK.
Example schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "contact_details",
"type": "object",
"properties": {
"fname": {
"type": "string"
},
"lname": {
"type": "string"
}
}
}
Code:
import memphis from 'memphis-dev';
import type { Memphis } from 'memphis-dev/types';
(async function () {
let memphisConnection: Memphis;
try {
memphisConnection = await memphis.connect({
host: 'MEMPHIS_BROKER_URL',
username: 'APPLICATION_TYPE_USERNAME',
password: 'PASSWORD'
});
const producer = await memphisConnection.producer({
stationName: 'STATION_NAME',
producerName: 'PRODUCER_NAME'
});
const headers = memphis.headers()
headers.add('key', 'value');
const msg = {
fname: "Bob",
lname: "Marley",
}
await producer.produce({
message: msg,
headers: headers
});
memphisConnection.close();
} catch (ex) {
console.log(ex);
}
})();
Last modified 1mo ago