Generate Command

November 27, 2025 · View on GitHub

The generate command is the primary function of the xRegistry Code Generation CLI. It transforms xRegistry message catalog definitions into production-ready, type-safe code for various languages and messaging platforms.

Synopsis

xrcg generate --projectname <name> --language <lang> --style <style> \
  --definitions <file-or-url> --output <dir> [options]

Options

OptionRequiredDescription
--projectname, -pYesThe project name used for namespaces, package names, and generated class prefixes. Should be a valid identifier (e.g., MyProject, ContosoEvents).
--language, -lYesTarget language for code generation. See Available Languages.
--style, -sYesThe code style/template to use, typically indicating the protocol and role (producer/consumer). See Available Styles.
--definitions, -dYesPath to a local file or URL containing xRegistry definitions (JSON or YAML).
--output, -oYesOutput directory for generated code. Will be created if it doesn't exist. Warning: Existing files may be overwritten.
--templates, -tNoPath to custom template directory. Templates here override built-in templates.
--template-argsNoExtra arguments passed to templates as key=value pairs. Can be specified multiple times.
--requestheadersNoHTTP headers for fetching remote definitions, as key=value. Useful for authenticated endpoints.
--messagegroupNoFilter to generate code for a specific message group only.
--endpointNoFilter to generate code for a specific endpoint only.

Available Languages

Language CodeDescriptionRuntime Requirements
javaJava 21+JDK 21+, Maven 3.8+
csC# / .NET.NET SDK 6.0+
pyPythonPython 3.9+
tsTypeScript/JavaScriptNode.js 18+, npm/yarn
asyncapiAsyncAPI 3.0 specificationNone (YAML output)
openapiOpenAPI 3.0 specificationNone (YAML output)
asaqlAzure Stream Analytics QueryNone (SQL output)

Available Styles

Styles determine the protocol binding and whether the generated code is a producer (sends messages) or consumer (receives messages).

Java Styles

StyleDescription
kafkaproducerApache Kafka producer using kafka-clients
kafkaconsumerApache Kafka consumer using kafka-clients
ehproducerAzure Event Hubs producer
ehconsumerAzure Event Hubs consumer
sbproducerAzure Service Bus producer
sbconsumerAzure Service Bus consumer
amqpproducerAMQP 1.0 producer (works with RabbitMQ 4+, Artemis, Qpid)
amqpconsumerAMQP 1.0 consumer
mqttclientMQTT 5.0 client (publish and subscribe)
producerGeneric producer (abstract base)
consumerGeneric consumer (abstract base)

C# Styles

StyleDescription
kafkaproducerApache Kafka producer using Confluent.Kafka
kafkaconsumerApache Kafka consumer
ehproducerAzure Event Hubs producer
ehconsumerAzure Event Hubs consumer
ehazfnAzure Event Hubs triggered Azure Function
sbproducerAzure Service Bus producer
sbconsumerAzure Service Bus consumer
sbazfnAzure Service Bus triggered Azure Function
egproducerAzure Event Grid producer
egazfnAzure Event Grid triggered Azure Function
amqpproducerAMQP 1.0 producer
amqpconsumerAMQP 1.0 consumer
mqttclientMQTT 5.0 client

Python Styles

StyleDescription
kafkaproducerApache Kafka producer using confluent-kafka
kafkaconsumerApache Kafka consumer
ehproducerAzure Event Hubs producer
ehconsumerAzure Event Hubs consumer
mqttclientMQTT 5.0 client using paho-mqtt

TypeScript Styles

StyleDescription
kafkaproducerApache Kafka producer using kafkajs
kafkaconsumerApache Kafka consumer
ehproducerAzure Event Hubs producer
ehconsumerAzure Event Hubs consumer
sbproducerAzure Service Bus producer
sbconsumerAzure Service Bus consumer
egproducerAzure Event Grid producer
amqpproducerAMQP 1.0 producer using rhea
amqpconsumerAMQP 1.0 consumer
mqttclientMQTT 5.0 client

AsyncAPI/OpenAPI Styles

StyleDescription
producerGenerates specification for message producers
consumerGenerates specification for message consumers
subscriber(OpenAPI only) CloudEvents subscription endpoint

Examples

Basic Code Generation

Generate a Python Kafka producer:

xrcg generate \
  --projectname PrinterEvents \
  --language py \
  --style kafkaproducer \
  --definitions ./inkjet.xreg.json \
  --output ./generated

Using Remote Definitions

Fetch definitions from a URL:

xrcg generate \
  --projectname MyEvents \
  --language java \
  --style ehproducer \
  --definitions https://registry.example.com/catalogs/events.json \
  --output ./generated

With Authentication Headers

For authenticated registry endpoints:

xrcg generate \
  --projectname MyEvents \
  --language cs \
  --style kafkaconsumer \
  --definitions https://registry.example.com/catalogs/events.json \
  --requestheaders "Authorization=Bearer token123" \
  --output ./generated

Filtering by Message Group

Generate code for a specific message group only:

xrcg generate \
  --projectname OrderEvents \
  --language java \
  --style kafkaproducer \
  --definitions ./full-catalog.json \
  --messagegroup "Contoso.ERP.OrderEvents" \
  --output ./generated

Using Custom Templates

Override built-in templates with your own:

xrcg generate \
  --projectname MyEvents \
  --language java \
  --style kafkaproducer \
  --definitions ./catalog.json \
  --templates ./my-custom-templates \
  --output ./generated

Template Arguments

Pass extra arguments to templates:

# AsyncAPI with binary CloudEvents mode
xrcg generate \
  --language asyncapi \
  --style producer \
  --projectname MyAPI \
  --definitions ./catalog.json \
  --template-args ce_content_mode=binary \
  --output ./generated

Generated Output Structure

The generated output varies by language but typically includes:

Java Project Structure

generated/
├── pom.xml                      # Maven build file with dependencies
├── src/main/java/
│   └── com/example/
│       ├── EventProducer.java   # Main producer class
│       ├── events/              # Generated event classes
│       └── data/                # Data classes from schemas
└── src/test/java/
    └── com/example/
        └── EventProducerTest.java  # Integration tests

Python Project Structure

generated/
├── pyproject.toml               # Project metadata and dependencies
├── src/
│   └── printerevents/
│       ├── __init__.py
│       ├── producer.py          # Main producer class
│       ├── events/              # Event type definitions
│       └── data/                # Data classes from schemas
└── tests/
    └── test_producer.py         # Integration tests with testcontainers

C# Project Structure

generated/
├── MyProject.csproj             # Project file with NuGet references
├── Program.cs                   # Entry point example
├── EventProducer.cs             # Main producer class
├── Events/                      # Event type definitions
├── Data/                        # Data classes from schemas
└── Tests/
    └── EventProducerTests.cs    # Integration tests

Schema Handling

The generator uses Avrotize to convert schemas between formats. Supported input schemas:

  • JSON Schema (draft-07, draft-2020-12)
  • Apache Avro
  • Protocol Buffers (proto3)

Schemas are automatically converted to the target language's native data structures with proper serialization support.

Error Handling

Common errors and solutions:

ErrorCauseSolution
Definition file not foundInvalid path or URLVerify the --definitions path exists
Invalid languageUnknown language codeUse xrcg list to see available languages
Invalid styleStyle not available for languageCheck available styles for your language
Schema conversion failedMalformed schema in definitionValidate your xRegistry document first

See Also