schema_registry

command module
v0.0.0-...-aef629f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

NATS Schema Registry Example

This example shows how to build a NATS Schema Registry using the NATS Service API and NATS KV Store.

This example allows you to register a schema, and then essentially become a "Gatekeeper" for your JetStream streams.

Usage

Run a NATS server with JetStream enabled:

nats-server -js

Run the example against a local NATS server:

go run .

Register a schema (you can use the sample.json in this repo):

cat sample.json | nats req '$SCHEMA.REGISTER.my_cool_schema'

Publish a message to a stream that uses the schema:

nats req '$SCHEMA.VALIDATE.numbers.foobar' 1 # This should work, and the message is passed to numbers.foobar
nats req '$SCHEMA.VALIDATE.numbers.foobar' abc # This should fail

TODO

I wrote this while on a stream, there is still plenty to add or improve:

  • Use natscontext to support different server addresses and credentials
  • Add a way to list all registered schemas
  • Respond with more appropriate error codes that are JetStream compatible when validation fails
  • Support a more graceful shutdown
  • Make KV backing configurable
  • Support more than just jsonschema

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL