xRegistry Codegen
Generate production-ready messaging code from xRegistry message and endpoint definitions for multiple languages and protocols.
Quick Start
Generate your first SDK
xrcg generate --language py --style kafkaproducer -d https://raw.githubusercontent.com/xregistry/codegen/main/samples/message-definitions/inkjet.xreg.json --output ./output --projectname PrinterEvents
Multi-Language Support
Generate code for C#, Java, Python, TypeScript, and Go with idiomatic patterns for each language.
Multiple Protocols
AMQP, MQTT, Kafka, HTTP, Azure Event Hubs, Azure Service Bus, Azure Event Grid, and more.
Schema Format Flexibility
Works with Apache Avro, JSON Schema, Protocol Buffers (protobuf), and XSD schema formats.
CloudEvents Native
First-class support for CloudEvents message format with proper type mappings and metadata handling.
Extensible Templates
Customizable Jinja2 templates allow you to tailor the generated code to your specific needs.
Production Ready
Generated code includes proper error handling, logging, tests, and follows best practices.
What You Get
Unlike snippet generators, this tool produces complete SDK-like projects:
๐ฏ Type-safe Clients
Producer/consumer classes with strongly-typed methods per message
๐ฆ Data Classes
Schema-derived classes via Avrotize (JSON Schema, Avro, Protobuf)
๐ง Build Files
pom.xml, .csproj, package.json, pyproject.toml with correct dependencies
๐งช Integration Tests
Docker-based tests using Testcontainers for Kafka, MQTT, AMQP brokers
๐ Project Structure
Language-idiomatic layout ready for IDE import
๐ Documentation
Generated README and inline documentation
Command Reference
The Generate Command
xrcg generate --projectname <name> --language <lang> --style <style> \
--definitions <file-or-url> --output <dir>
| Option | Description |
|---|---|
--projectname | Project/namespace name for generated code |
--language | Target language: java, cs, py, ts, go, asyncapi, openapi |
--style | Protocol binding: kafkaproducer, ehconsumer, mqttclient, etc. |
--definitions, -d | Path or URL to xRegistry JSON/YAML definition |
--output, -o | Output directory (will be created/overwritten) |
--templates | Custom template directory (optional) |
--template-args | Extra args as key=value (optional) |
Other Commands
List available templates
xrcg list
Validate definition files
xrcg validate --definitions ./catalog.json
Configure defaults
xrcg config set defaults.language java
xrcg config set defaults.output_dir ./generated
xrcg config list
Example Usage
Apache Kafka
# Python Kafka Producer
xrcg generate --language py --style kafkaproducer -d contoso-erp.xreg.json -o ./output
# C# Kafka Consumer
xrcg generate --language cs --style kafkaconsumer -d contoso-erp.xreg.json -o ./output
# Java Kafka Producer
xrcg generate --language java --style kafkaproducer -d contoso-erp.xreg.json -o ./output
Azure Event Hubs
# TypeScript Event Hubs Producer
xrcg generate --language ts --style ehproducer -d fabrikam-motorsports.xreg.json -o ./output
# C# Event Hubs Consumer
xrcg generate --language cs --style ehconsumer -d fabrikam-motorsports.xreg.json -o ./output
MQTT 5.0
# Python MQTT Client
xrcg generate --language py --style mqttclient -d lightbulb.xreg.json -o ./output
# Java MQTT Client
xrcg generate --language java --style mqttclient -d lightbulb.xreg.json -o ./output
Available Templates
C# / .NET 6+
kafkaproducer,kafkaconsumerehproducer,ehconsumer,ehazfnsbproducer,sbconsumer,sbazfnegproducer,egazfnamqpproducer,amqpconsumermqttclient
Java 21+
kafkaproducer,kafkaconsumerehproducer,ehconsumersbproducer,sbconsumeramqpproducer,amqpconsumermqttclient
Python 3.9+
kafkaproducer,kafkaconsumerehproducer,ehconsumeramqpproducer,amqpconsumermqttclient
TypeScript
kafkaproducer,kafkaconsumerehproducer,ehconsumersbproducer,sbconsumeregproduceramqpproducer,amqpconsumermqttclient
Go
kafkaproducer,kafkaconsumer
๐ Specifications
asyncapi- AsyncAPI 3.0openapi- OpenAPI 3.0- Azure Stream Analytics
What is xRegistry?
xRegistry is a CNCF project defining a standard format for describing messaging and eventing infrastructure. A message catalog document contains:
- Schema groups โ Payload schemas (JSON Schema, Avro, Protobuf)
- Message groups โ Message definitions with CloudEvents envelope metadata
- Endpoints โ Protocol bindings (Kafka topics, AMQP queues, HTTP endpoints)
The code generator follows references between these elements to produce cohesive, type-safe SDKs.
Sample Definitions
Try these sample definitions from the repository:
| File | Description |
|---|---|
contoso-erp.xreg.json | ERP system events (orders, payments, inventory) |
fabrikam-motorsports.xreg.json | Motorsports telemetry stream (Avro schema) |
inkjet.xreg.json | IoT printer events (Avro schema) |
smartoven-jsonschema.xreg.json | Smart oven IoT events (JSON Schema) |
lightbulb.xreg.json | Smart lightbulb device events (Avro schema) |