xRegistry Codegen

Generate production-ready messaging code from xRegistry message and endpoint definitions for multiple languages and protocols.

Quick Start

Docker

Recommended
docker pull ghcr.io/xregistry/codegen/xrcg:latest

No Python required. Works on Linux, macOS, and Windows.

Note: File paths must be relative to your current directory due to Docker volume mapping.

Shell alias for convenience
Linux/macOS
alias xrcg='docker run --rm -v $(pwd):/work ghcr.io/xregistry/codegen/xrcg:latest'
PowerShell
function xrcg { docker run --rm -v ${PWD}:/work ghcr.io/xregistry/codegen/xrcg:latest $args }

Python

pip install xrcg

Requires Python 3.10+

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

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>
OptionDescription
--projectnameProject/namespace name for generated code
--languageTarget language: java, cs, py, ts, go, asyncapi, openapi
--styleProtocol binding: kafkaproducer, ehconsumer, mqttclient, etc.
--definitions, -dPath or URL to xRegistry JSON/YAML definition
--output, -oOutput directory (will be created/overwritten)
--templatesCustom template directory (optional)
--template-argsExtra 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

Available Templates

C# / .NET 6+

  • kafkaproducer, kafkaconsumer
  • ehproducer, ehconsumer, ehazfn
  • sbproducer, sbconsumer, sbazfn
  • egproducer, egazfn
  • amqpproducer, amqpconsumer
  • mqttclient

Java 21+

  • kafkaproducer, kafkaconsumer
  • ehproducer, ehconsumer
  • sbproducer, sbconsumer
  • amqpproducer, amqpconsumer
  • mqttclient

Python 3.9+

  • kafkaproducer, kafkaconsumer
  • ehproducer, ehconsumer
  • amqpproducer, amqpconsumer
  • mqttclient

TypeScript

  • kafkaproducer, kafkaconsumer
  • ehproducer, ehconsumer
  • sbproducer, sbconsumer
  • egproducer
  • amqpproducer, amqpconsumer
  • mqttclient

Go

  • kafkaproducer, kafkaconsumer

๐Ÿ“„ Specifications

  • asyncapi - AsyncAPI 3.0
  • openapi - 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:

FileDescription
contoso-erp.xreg.jsonERP system events (orders, payments, inventory)
fabrikam-motorsports.xreg.jsonMotorsports telemetry stream (Avro schema)
inkjet.xreg.jsonIoT printer events (Avro schema)
smartoven-jsonschema.xreg.jsonSmart oven IoT events (JSON Schema)
lightbulb.xreg.jsonSmart lightbulb device events (Avro schema)

Community