Franz.Common.Messaging.Hosting.Kafka 2.2.16

dotnet add package Franz.Common.Messaging.Hosting.Kafka --version 2.2.16
 
NuGet\Install-Package Franz.Common.Messaging.Hosting.Kafka -Version 2.2.16
 
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="Franz.Common.Messaging.Hosting.Kafka" Version="2.2.16" />
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Franz.Common.Messaging.Hosting.Kafka" Version="2.2.16" />
 
Directory.Packages.props
<PackageReference Include="Franz.Common.Messaging.Hosting.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 Franz.Common.Messaging.Hosting.Kafka --version 2.2.16
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Franz.Common.Messaging.Hosting.Kafka, 2.2.16"
 
#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 Franz.Common.Messaging.Hosting.Kafka@2.2.16
 
#: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=Franz.Common.Messaging.Hosting.Kafka&version=2.2.16
 
Install as a Cake Addin
#tool nuget:?package=Franz.Common.Messaging.Hosting.Kafka&version=2.2.16
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Franz.Common.Messaging.Hosting.Kafka

A Kafka hosting integration for the Franz Framework that connects the Kafka transport layer (Franz.Common.Messaging.Kafka) to the .NET hosting runtime (Microsoft.Extensions.Hosting).

This package is responsible only for:

  • background execution
  • hosted listeners
  • message dispatch orchestration

🧱 Kafka transport, producers, consumers, and configuration live in
Franz.Common.Messaging.Kafka


✨ Features

Hosted Services

  • KafkaHostedService
    Runs a Kafka listener inside a .NET BackgroundService.

  • MessagingHostedService
    Orchestrates message dispatch:

    • creates scoped execution contexts
    • resolves messaging strategies
    • dispatches messages safely
  • OutboxHostedService
    Publishes messages stored in an outbox (SQL / Mongo) to Kafka reliably.

Dependency Injection Extensions

  • KafkaHostingServiceCollectionExtensions
  • Simple registration via:
    • AddKafkaHostedListener()
    • AddOutboxHostedListener()

Separation of Concerns

  • No Kafka configuration here
  • No Kafka consumer creation here
  • Hosting depends on abstractions only

Observability

  • Structured logging
  • Emoji-based lifecycle signals
  • Compatible with OpenTelemetry
  • Correlation via MessageContextAccessor

πŸ“‚ Project Structure

Franz.Common.Messaging.Hosting.Kafka/
β”œβ”€β”€ Extensions/
β”‚ └── KafkaHostingServiceCollectionExtensions.cs
β”œβ”€β”€ HostedServices/
β”‚ β”œβ”€β”€ KafkaHostedService.cs
β”‚ β”œβ”€β”€ MessagingHostedService.cs
β”‚ └── OutboxHostedService.cs
└── README.md

βš™οΈ Dependencies

  • Microsoft.Extensions.Hosting (10.0.0)
  • Microsoft.Extensions.DependencyInjection.Abstractions (10.0.0)
  • Franz.Common.Messaging
  • Franz.Common.Messaging.Kafka
  • Franz.Common.Messaging.Hosting

⚠️ This package assumes Kafka transport is already registered via Franz.Common.Messaging.Kafka.


πŸš€ Usage

1️⃣ Register Kafka Transport (required)

using Franz.Common.Messaging.Kafka.Extensions;
services.AddKafkaMessaging(configuration);

2️⃣ Register Kafka Hosted Services

using Franz.Common.Messaging.Hosting.Kafka.Extensions;
services.AddKafkaHostedListener(configuration);
services.AddOutboxHostedListener(configuration);

This will:

  • start background Kafka consumption
  • dispatch messages through Franz messaging strategies
  • process outbox messages reliably

πŸ”„ Kafka Hosted Service Lifecycle

public sealed class KafkaHostedService : BackgroundService
{
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
 // Subscribes to Kafka topics
 // Listens until host shutdown
 // Dispatches messages safely
 }
}

Behavior:

  • graceful shutdown
  • no host crashes on bad messages
  • scope-per-message execution

πŸ“¦ Outbox Hosted Service

public sealed class OutboxHostedService : BackgroundService
{
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
 // Reads outbox
 // Publishes to Kafka
 // Handles retries & DLQ
 }
}

Guarantees:

  • at-least-once delivery
  • retry control
  • no message loss on crashes

πŸ“Š Observability

  • Emoji logging conventions:

    • πŸš€ startup
    • πŸ›‘ shutdown
    • ⚠️ recoverable failure
    • ❌ execution error
    • πŸ”₯ DLQ
  • Correlation IDs via MessageContextAccessor

  • OpenTelemetry-compatible spans


🧭 Architectural Role

Concern Package
Kafka transport Franz.Common.Messaging.Kafka
Kafka consumer creation Franz.Common.Messaging.Kafka
Hosted execution Franz.Common.Messaging.Hosting.Kafka
Dispatch orchestration Franz.Common.Messaging.Hosting.Kafka

This ensures:

  • clean Testcontainers integration
  • deterministic CI behavior
  • no hidden threads
  • safe message handling

🧾 Version Information

  • Current Version: v2.2.16
  • Target Framework: .NET 10.0
  • Part of the Franz Framework

πŸ“– Changelog

v2.0.1 – Internal Modernization

  • Messaging and infrastructure refactored for async, thread-safety, and modern .NET 10 patterns.
  • All APIs remain fully backward compatible.
  • Tests, listeners, and pipeline components modernized.

Version 1.7.01

  • 🧱 Enforced strict separation between Kafka transport and hosting
  • πŸ”Œ Removed Kafka consumer creation from hosting layer
  • πŸ”„ Hosting now depends exclusively on IListener
  • ♻️ Fixed lifecycle handling and graceful shutdown
  • πŸ§ͺ Improved Testcontainers and CI reliability
  • ⬆️ Upgraded to .NET 10.0

Version 1.6.20

  • Initial Kafka hosting support
  • Added KafkaHostedService
  • Added OutboxHostedService
  • Introduced hosting DI extensions
  • Integrated MessageContextAccessor
  • Emoji-based logging conventions

πŸ“œ License

MIT License See the LICENSE file for details.

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 Franz.Common.Messaging.Hosting.Kafka:

Package Downloads
Franz.Common.Http.Messaging

Shared utility library for the Franz Framework.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.16 50 7/2/2026
2.2.15 101 6/29/2026
2.2.14 99 6/29/2026
2.2.13 103 6/29/2026
2.2.12 104 6/28/2026
2.2.11 111 6/28/2026
2.2.10 103 6/28/2026
2.2.9 109 6/28/2026
2.2.8 100 6/28/2026
2.2.7 116 6/7/2026
2.2.6 113 6/6/2026
2.2.5 116 6/4/2026
2.2.4 113 6/3/2026
2.2.3 97 6/2/2026
2.2.2 107 6/2/2026
2.2.1 103 5/24/2026
2.1.4 108 4/27/2026
2.1.3 101 4/26/2026
2.1.2 105 4/26/2026
2.1.1 114 4/22/2026
Loading failed