Optima.Net.Events 1.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Optima.Net.Events --version 1.0.2
                    
NuGet\Install-Package Optima.Net.Events -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Optima.Net.Events" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Optima.Net.Events" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Optima.Net.Events" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Optima.Net.Events --version 1.0.2
                    
#r "nuget: Optima.Net.Events, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Optima.Net.Events@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Optima.Net.Events&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Optima.Net.Events&version=1.0.2
                    
Install as a Cake Tool

Optima.Net.Events

A self-validating event serialization framework for .NET supporting Avro and Protobuf.
It provides schema-driven serialization, payload normalization, and forward/backward compatibility for distributed event-driven systems.

If you like what I did here or it inspired you to learn something new, please consider buying me a coffee: https://buymeacoffee.com/snamretsuek The support would be greatly appreciated!


Overview

Optima.Net.Events enables schema-safe event exchange between microservices using either Avro or Protobuf.
It handles field normalization, schema validation, and ensures your events remain compatible across versions.


Features

Core Capabilities

  • Generic event model with dynamic payloads (GenericEvent<TPayload> and DynamicPayload)
  • Self-validating Avro-based serialization and deserialization
  • Schema generation for both Avro (.avsc) and Protobuf (.proto)
  • Payload normalization that ensures Avro and Protobuf-safe field names
  • Optional<T> support with built-in JSON converters
  • Backward and forward compatibility handling
  • Case-insensitive deserialization and graceful handling of missing fields

Example: Avro Event Serialization

var payload = new DynamicPayload("PaymentRequested");
payload.Add("SourceAccountNumber", "123456789");
payload.Add("TargetAccountNumber", "987654321");
payload.Add("Amount", 1500.75);
payload.Add("Currency", "USD");

var evt = new GenericEvent<DynamicPayload>
{
    EventId = Guid.NewGuid(),
    EventType = payload.PayloadName,
    Source = "PaymentsService",
    SchemaVersion = "V1.0.0",
    Timestamp = DateTime.UtcNow,
    Payload = payload
};

// Generate Avro schema
var schemaJson = AvroSchemaGenerator.GenerateSchemaFromGenericEvent(evt);
Console.WriteLine(schemaJson);

// Serialize and deserialize
var data = AvroEventSerializer.Serialize(evt, schemaJson);
var result = AvroEventSerializer.Deserialize(data, schemaJson);

// Output event before and after serialization
Console.WriteLine(JsonHelper.Serialize(evt, true));
Console.WriteLine(JsonHelper.Serialize(result, true));

Example: Protobuf Event Serialization

var payload = new DynamicPayload("PaymentRequested");
payload.Add("SourceAccountNumber", "123456789");
payload.Add("SourceFirstName", "Marcus");
payload.Add("SourceLastName", "Keulen");
payload.Add("TargetAccountNumber", "987654321");
payload.Add("TargetFirstName", "Jane");
payload.Add("Amount", "1500.75");
payload.Add("Currency", "USD");

var evt = new GenericEvent<DynamicPayload>
{
    EventId = Guid.NewGuid(),
    EventType = payload.PayloadName,
    Source = "PaymentsService",
    SchemaVersion = "V1.0.0",
    Timestamp = DateTime.UtcNow,
    Payload = payload
};

// Generate Protobuf schema
var protoSchema = ProtobufSchemaGenerator.GenerateSchemaProto(payload.Fields, payload.PayloadName);

// Serialize
var data = ProtobufEventSerializer.Serialize(evt);

// Deserialize (requires schema)
var result = ProtobufEventSerializer.Deserialize<DynamicPayload>(data, protoSchema);

// Print results
Console.WriteLine(JsonHelper.Serialize(evt, true));
Console.WriteLine(JsonHelper.Serialize(result, true));

CLI Schema Generation

It is strongly recommended that developers implement a CLI utility using the schema generator functions to pre-generate schemas for all events.

You can then store these .avsc or .proto files in a central schema directory or registry.
At runtime, your services can retrieve these schemas and pass them to the relevant serializer methods.

Example CLI command concept:

dotnet run -- generate-schema --type PaymentRequested --output ./schemas

This ensures:

  • Consistent schema evolution across all services
  • Reproducible serialization and deserialization
  • Safe backward and forward compatibility

Comparison

Feature Avro Protobuf
Schema Type JSON (.avsc) Text (.proto)
Flexibility High (runtime schemas) Medium (compiled or attribute-based)
Performance Moderate 55 microsecond Very fast 15 microseconds average over
average over a 1000 a 1000 iterations.
iterations
Payload Model Dynamic or typed Typed (via attributes)
Schema Evolution Native support Manual field numbering

You should do your own benchmark testing. Those execution times are not cast in stone and depend greatly on how your event is structured. This times were recoded using the Event, in the excamples.

Planned Modules

  • Optima.Net.Events.Kafka � native Kafka producer/consumer support using Avro and Protobuf.
  • Schema Registry Integration � automatic schema storage and retrieval.
  • Automatic Schema Hashing and Version Matching � ensure schema alignment between services.

Compatibility

  • .NET 8.0 or later
  • Cross-platform: Windows, Linux, macOS

License

MIT License � 2025

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Optima.Net.Events:

Package Downloads
Optima.Net.DomainModel

Optima.Net.DomainModel Defines the immutable structural foundation of the domain, enforcing invariants and preventing illegal domain states without handling behavior, workflows, or persistence.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 105 3/4/2026
1.0.6 116 1/17/2026
1.0.5 154 1/8/2026
1.0.4 120 1/8/2026
1.0.3 467 11/19/2025
1.0.2 294 11/12/2025
1.0.1 287 11/12/2025
1.0.0 276 11/10/2025

RELEASENOTES.md