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
<PackageReference Include="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" Version="1.0.0" />
<PackageVersion Include="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" Version="1.0.0" />
<PackageReference Include="Anarchy.Toolkit.Infrastructure.Messaging.Kafka" />
paket add Anarchy.Toolkit.Infrastructure.Messaging.Kafka --version 1.0.0
#r "nuget: Anarchy.Toolkit.Infrastructure.Messaging.Kafka, 1.0.0"
#:package Anarchy.Toolkit.Infrastructure.Messaging.Kafka@1.0.0
#addin nuget:?package=Anarchy.Toolkit.Infrastructure.Messaging.Kafka&version=1.0.0
#tool nuget:?package=Anarchy.Toolkit.Infrastructure.Messaging.Kafka&version=1.0.0
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 | Versions 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. |
-
net10.0
- Anarchy.Toolkit.Core.Messaging.Abstractions (>= 3.0.0)
- Anarchy.Toolkit.Core.Telemetry (>= 1.0.1)
- Confluent.Kafka (>= 2.16.0)
- Humanizer (>= 3.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Diagnostics (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Newtonsoft.Json (>= 13.0.4)
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.