Anarchy.Toolkit.Infrastructure.Messaging.Kafka 1.0.0

dotnet add package Anarchy.Toolkit.Infrastructure.Messaging.Kafka --version 1.0.0
                    
NuGet\Install-Package Anarchy.Toolkit.Infrastructure.Messaging.Kafka -Version 1.0.0
                    
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="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" />
                    
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 Anarchy.Toolkit.Infrastructure.Messaging.Kafka --version 1.0.0
                    
#r "nuget: Anarchy.Toolkit.Infrastructure.Messaging.Kafka, 1.0.0"
                    
#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 Anarchy.Toolkit.Infrastructure.Messaging.Kafka@1.0.0
                    
#: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=Anarchy.Toolkit.Infrastructure.Messaging.Kafka&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Anarchy.Toolkit.Infrastructure.Messaging.Kafka&version=1.0.0
                    
Install as a Cake Tool

Anarchy.Toolkit.Infrastructure.Messaging.Kafka

Part of Anarchy I/O Toolkit · Pillar: Infrastructure · Layer: Infrastructure · Package catalog

Apache Kafka publisher and inbound mapper for Core.Messaging.Abstractions, using the Confluent .NET client. Works with Kafka-compatible brokers; no AWS, CloudEvents or outbox dependency.

using Anarchy.Toolkit.Core.Composition.Extension.Microsoft.DependencyInjection;
using Anarchy.Toolkit.Infrastructure.Messaging.Kafka.DependencyInjection.Module;
using Confluent.Kafka;

services.UseModule(new ModuleKafkaMessageBroker(cfg => new ProducerConfig {
    BootstrapServers = cfg["Kafka:BootstrapServers"],
    EnableIdempotence = true
}), configuration, environment);
// Register AppTelemetry separately, e.g. services.AddCoreTelemetry().
// Resolve [FromKeyedServices("kafka")] IMessageBrokerPublisher.

AddKafkaMessageBroker(config) is also available. The container owns and disposes the producer; a manually constructed publisher does not own it. Configure authentication, durability, timeout and producer options yourself. Use broker acknowledgement settings appropriate to the application; do not set Acks=0 when acknowledgement is required.

Mapping and delivery

Destination is the Kafka topic; body and partition key are UTF-8 string value and key. Custom attributes become UTF-8 headers. anarchy-message-id and anarchy-deduplication-id are reserved headers; collisions are rejected. The ID is preserved; the optional deduplication ID is carried but not enforced by Kafka. Producer idempotence does not deduplicate separate application-level publishes. Inbound mapping uses the ID header, or topic:partition:offset when absent; BrokerReference always contains that opaque location. It rejects duplicate, null or invalid UTF-8 headers, tombstones and empty bodies. The mapper strips its two reserved headers from attributes.

Inbound invalid headers throw KafkaHeaderMappingException, with specific duplicate, null-value and invalid-encoding subtypes and the offending HeaderName. These remain catchable as ArgumentException; invalid UTF-8 retains the original DecoderFallbackException as its inner exception. Because the .NET decoder exception is sealed, it cannot also be the base of the specialized mapping exception. Reserved or null outbound attributes and partition-end notifications have their own argument exception types.

Call KafkaMessageMapper.FromKafka(consumeResult) in your own consumer loop. Offset management, committing only after successful processing, retry and poison-message policy are the application's responsibility. Offset commits are not per-message acknowledgements, and Kafka may redeliver. There is no consumer loop, transaction, outbox, or exactly-once guarantee in this package.

Batch publishing sends one record per chunk in input order, including across topics. Before/after callbacks run once per attempted record except when cancellation interrupts the attempt; a before failure skips that record, and an after failure is reported as a chunk failure even if delivery succeeded. continueOnFailure continues with subsequent records and can break ordering. Cancellation propagates; a cancelled or timed-out send may still reach Kafka, so retry using application-level idempotency. Empty batches do nothing. The matching Testing.Kafka kit provides a fixture and a real consumer for broker-backed tests.

Releases

See the release notes for the complete release history.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 Anarchy.Toolkit.Infrastructure.Messaging.Kafka:

Package Downloads
Anarchy.Toolkit.Testing.Kafka

Kafka message fixture and consumer helper for tests against a Kafka-compatible broker.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 45 11/24/2026

## Releases

### 1.0.0

- Introduced a Kafka message publisher, inbound mapping and dependency-injection module.