ποΈ schemreg
Async schema registry client for Confluent Schema Registry (and Karapace / Apicurio) and AWS Glue Schema Registry, with:
- β‘ Zero-copy wire-format encode / decode (Confluent 5-byte header, Glue 18-byte header)
- π Transparent in-memory caching with thundering-herd coalescing
- π Pluggable backend via the
SchemaRegistryClienttrait - π― Feature-gated: pull in only what you need
β¨ Features
| Feature | Enables |
|---|---|
| (none) | π§ Core types, wire format helpers, traits, Glue wire format |
confluent |
π Confluent HTTP client, encoder, decoder, TLS via rustls + webpki-roots |
glue |
βοΈ AWS Glue SDK client (AwsGlueSchemaRegistry), ZLIB compression via flate2 |
avro |
πͺΆ Avro encode / decode via apache-avro, works with any SchemaRegistryClient |
native-tls-roots |
π rustls-native-certs (implies confluent) |
aws-lc-rs |
π AWS LC crypto backend instead of ring (implies confluent) |
π Quick start
π Confluent Schema Registry
# Cargo.toml
[]
= { = "0.1", = ["confluent"] }
= { = "1", = ["full"] }
= "1"
use Arc;
use ;
use Bytes;
async
βοΈ AWS Glue Schema Registry
[]
= { = "0.1", = ["glue"] }
= { = "1", = ["full"] }
= "1"
use ;
With the glue feature and real AWS credentials you can use the high-level AwsGlueSchemaRegistry client:
use BehaviorVersion;
use AwsGlueSchemaRegistry;
let config = load_defaults.await;
let registry = from_config;
π¬ Wire formats
π Confluent Schema Registry
Byte offset 0 1 2 3 4 5 β¦
ββββββββββ¬βββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β 0x00 β schema_id (u32 BE) β payload (N bytes) β
ββββββββββ΄βββββββββββββββββββββββββββββ΄βββββββββββββββββββββββ
magic ββββββββββ 4 bytes ββββββββββββ
βοΈ AWS Glue Schema Registry
Byte offset 0 1 2 18 18 β¦
ββββββββββ¬βββββββββ¬βββββββββββββββββββββ¬βββββββββββββββββββββββ
β 0x03 β comp β schema_version_id β payload (N bytes) β
ββββββββββ΄βββββββββ΄βββββββββββββββββββββ΄βββββββββββββββββββββββ
version βbyte βββββββ 16 bytes βββββββ
- comp:
0x00= none,0x05= ZLIB - schema_version_id: 128-bit UUID stored as big-endian bytes
π Custom backend
Any struct that implements SchemaRegistryClient can be used as the backend:
use ;
use Result;
// Wrap with cache transparently:
use CachedSchemaRegistry;
let cached = new;
See examples/custom_backend.rs for a full working example.
β‘ Cache management
CachedSchemaRegistry exposes the AnySchemaCache trait for lifecycle control:
use ;
let cached = with_max_entries;
// Pre-warm for known schema IDs (avoids cold-miss latency on startup).
cached.warm_cache.await?;
println!;
// Invalidate a single stale entry.
cached.invalidate;
// Wipe everything.
cached.clear_cache;
π Format-agnostic decoding
WireFormatDecoder auto-detects the wire format and dispatches to the correct backend:
use WireFormatDecoder;
let decoder = new
.confluent
.glue; // requires `glue` feature
let msg = decoder.decode.await?;
println!; // Avro / Protobuf / Json / Unknown
println!;
π Examples
| Example | Description |
|---|---|
confluent_encode_decode |
π Full encodeβdecode round-trip with an in-memory stub registry |
avro_roundtrip |
πͺΆ End-to-end Avro encode β Confluent wire format β decode |
glue_roundtrip |
βοΈ Glue wire format encode / decode, optional ZLIB compression |
custom_backend |
π Implementing SchemaRegistryClient + cache + WireFormatDecoder |
π License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.