Franz.Common.Messaging.Kafka 2.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Franz.Common.Messaging.Kafka --version 2.2.2
                    
NuGet\Install-Package Franz.Common.Messaging.Kafka -Version 2.2.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="Franz.Common.Messaging.Kafka" Version="2.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Franz.Common.Messaging.Kafka" Version="2.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Franz.Common.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 Franz.Common.Messaging.Kafka --version 2.2.2
                    
#r "nuget: Franz.Common.Messaging.Kafka, 2.2.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 Franz.Common.Messaging.Kafka@2.2.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=Franz.Common.Messaging.Kafka&version=2.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Franz.Common.Messaging.Kafka&version=2.2.2
                    
Install as a Cake Tool

Franz.Common.Messaging.Kafka

A Kafka transport integration for the Franz Framework, designed to provide clean, deterministic, and production-grade interaction with Kafka topics, producers, and consumers.

This package focuses exclusively on Kafka transport concerns: configuration, producers, consumers, serialization, and transactions.

๐Ÿงฑ Hosting, background execution, and listeners are intentionally not handled here. They live in Franz.Common.Messaging.Hosting.Kafka.


โœจ Features

Kafka Transport & Configuration

  • Centralized Kafka configuration via MessagingOptions
  • ConnectionProvider and ConnectionFactoryProvider for managing Kafka connections
  • Deterministic, DI-friendly Kafka setup

Kafka Producers

  • MessagingPublisher for publishing integration events
  • MessagingSender for point-to-point messaging
  • Automatic topic resolution and naming strategies

Kafka Consumers

  • Native usage of Confluent.Kafka.IConsumer<string, string>
  • IKafkaConsumerFactory as the single authority for consumer creation
  • Correct lifetime management aligned with Kafka consumer group semantics

Modeling

  • KafkaModel and ModelProvider for Kafka-based domain modeling
  • Strong separation between messaging models and business logic

Serialization

  • IMessageDeserializer
  • JsonMessageDeserializer
  • Deterministic JSON serialization using Franz messaging contracts

Transactions

  • MessagingTransaction for Kafka-backed transactional workflows

Utilities

  • ExchangeNamer and TopicNamer for consistent topic naming
  • Messaging helpers shared across Franz transports

Dependency Injection

  • Fluent ServiceCollectionExtensions for Kafka transport registration
  • No accidental hosting or background execution side effects

๐Ÿงญ Architectural Scope

This package is transport-only.

Responsibility Package
Kafka producers โœ… Franz.Common.Messaging.Kafka
Kafka consumers (transport) โœ… Franz.Common.Messaging.Kafka
Background listeners โŒ
Hosted services โŒ
Message dispatch pipelines โŒ
Hosting / workers โžœ Franz.Common.Messaging.Hosting.Kafka

This separation ensures:

  • Testability with Testcontainers
  • Clean CI/CD pipelines
  • No hidden threads or background services
  • Reuse in CLI tools, workers, APIs, and serverless contexts

๐Ÿ“ฆ Dependencies

This package depends on:

  • Confluent.Kafka (2.3.0)
    Core Kafka client implementation

  • Franz.Common.Messaging
    Core messaging abstractions and contracts

  • Franz.Common.Annotations
    Messaging and modeling annotations

โš ๏ธ Hosting integration is intentionally excluded. Use Franz.Common.Messaging.Hosting.Kafka for background listeners.


๐Ÿ“ฅ Installation

From NuGet

dotnet add package Franz.Common.Messaging.Kafka

๐Ÿš€ Usage

1๏ธโƒฃ Register Kafka Transport

using Franz.Common.Messaging.Kafka.Extensions;

public void ConfigureServices(IServiceCollection services)
{
    services.AddKafkaMessaging(configuration);
}

This registers:

  • Kafka producers
  • Kafka senders
  • Kafka consumers (transport only)

No hosted services are started.


2๏ธโƒฃ Publish Messages

public class OrderPublisher
{
    private readonly IMessagingPublisher _publisher;

    public OrderPublisher(IMessagingPublisher publisher)
    {
        _publisher = publisher;
    }

    public async Task PublishAsync(OrderCreatedEvent evt)
    {
        await _publisher.PublishAsync(evt);
    }
}

3๏ธโƒฃ Send Messages

public class PaymentSender
{
    private readonly IMessagingSender _sender;

    public PaymentSender(IMessagingSender sender)
    {
        _sender = sender;
    }

    public async Task SendAsync(PaymentCommand command)
    {
        await _sender.SendAsync(command);
    }
}

4๏ธโƒฃ Kafka Consumers (Important)

Franz does not re-abstract Kafka consumers.

Consumers are provided directly by Confluent:

IConsumer<string, string>

They are:

  • Created by IKafkaConsumerFactory
  • Registered as long-lived singletons
  • Fully compatible with Confluent.Kafka tooling and documentation

This avoids:

  • Interface drift
  • Partial re-implementations
  • Subtle incompatibilities during upgrades

๐Ÿงช Testing & CI

This design is fully compatible with:

  • Testcontainers (Kafka)
  • Azure DevOps pipelines
  • Docker-based integration tests
  • Local developer environments

Because:

  • No background services auto-start
  • No implicit threads are created
  • Kafka consumers are explicit and controlled

๐Ÿ”— Integration with the Franz Framework

This package integrates with:

  • Franz.Common.Messaging
  • Franz.Common.Messaging.Hosting.Kafka (optional, for background execution)
  • Franz.Common.Mediator
  • Franz.Common.EntityFramework
  • Franz.Common.Business

Kafka is treated as a transport, not an execution model.


๐Ÿงพ Versioning & Changelog

- Current Version: 2.2.2

Version 1.7.01

  • ๐Ÿงฑ Corrected transport vs hosting separation
  • ๐Ÿ”Œ Removed Kafka consumer re-abstraction
  • ๐Ÿญ Centralized consumer creation via IKafkaConsumerFactory
  • โ™ป๏ธ Fixed DI lifetimes for Kafka consumers
  • ๐Ÿงฉ Clean separation between messaging and hosting layers
  • ๐Ÿงช Improved Testcontainers and CI reliability

v2.0.2 โ€“ Internal Modernization

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

๐Ÿ“„ License

MIT License See the LICENSE file for details.


๐Ÿง  Final Note

This package intentionally mirrors enterprise messaging frameworks (MassTransit, NServiceBus, Brighter) by enforcing:

Transport โ‰  Hosting

That separation is what makes Franz:

  • Predictable
  • Testable
  • Scalable
  • Production-safe
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.Kafka:

Package Downloads
Franz.Common.Messaging.Hosting.Kafka

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.7 121 6/7/2026
2.2.6 120 6/6/2026
2.2.5 124 6/4/2026
2.2.4 116 6/3/2026
2.2.3 136 6/2/2026
2.2.2 150 6/2/2026
2.2.1 136 5/24/2026
2.1.4 141 4/27/2026
2.1.3 131 4/26/2026
2.1.2 129 4/26/2026
2.1.1 140 4/22/2026
2.0.2 148 3/30/2026
2.0.1 140 3/29/2026
1.7.8 148 3/2/2026
1.7.7 166 1/31/2026
1.7.6 153 1/22/2026
1.7.5 169 1/10/2026
1.7.4 152 12/27/2025
1.7.3 247 12/22/2025
1.7.2 232 12/21/2025
Loading failed