MessageHook.Kafka 1.0.0

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

MessageHook.Kafka

Kafka integration for MessageHook — a testing framework that lets you produce a Kafka message and wait for the response in a single step, with built-in correlation ID and message key filtering.

Installation

dotnet add package MessageHook.Kafka

Installing MessageHook.Kafka automatically pulls MessageHook.Orchestration and MessageHook.Core.

Setup

Register MessageHook in your test project's DI setup:

services.AddKafkaMessageHook(builder =>
{
    builder.ConfigureBroker(broker =>
        {
            broker.WithBootstrapServers(new[] { "localhost:9092" });
        })
        .AddConsumer(consumer =>
        {
            consumer.AddTopic("response-topic")
                    .AddConsumerGroup("my-test-group")
                    .AddConsumingSerializer(new KafkaUTF8Serializer())
                    .AddConsumingType(typeof(MyResponseType));
        })
        .AddProducer(producer =>
        {
            producer.AddProducerTopic("request-topic")
                    .AddProducerSerializer(new KafkaUTF8Serializer());
        });
});

Usage

Correlation ID mode (default)

Produce a message and wait for a response that carries the same correlation ID:

var factory = provider.GetRequiredService<IMessageHookFactory>();

var step = await factory.CreateMessageHookStepAsync(new MessageHookConfiguration
{
    ProduceTo   = "request-topic",
    ConsumeFrom = new[] { "response-topic" },
    ConsumingOptions = new ConsumingOptionsConfiguration
    {
        TimeOut          = TimeSpan.FromSeconds(30),
        MsgReceivedCount = 1
    }
});

var result = await step.ExecuteAsync("correlation-id", myPayload);
var messages = await result.Task;

Message key mode

Filter consumed messages by a specific Kafka message key:

var step = await factory.CreateMessageHookStepAsync(new MessageHookConfiguration
{
    ProduceTo   = "request-topic",
    ConsumeFrom = new[] { "response-topic" },
    ConsumingOptions = new ConsumingOptionsConfiguration
    {
        TimeOut          = TimeSpan.FromSeconds(30),
        MsgReceivedCount = 1,
        ExpectedMessageKey = "my-key"
    }
});

var result = await step.ExecuteAsync("my-key", myPayload);
var messages = await result.Task;

Produce with headers

var result = await step.ExecuteAsync("my-key", myPayload, new ProducingExtraData
{
    Headers = new Dictionary<string, string> { { "x-source", "integration-test" } }
});

EchoService

The repo includes MessageHook.EchoService — a ready-made Kafka echo service that consumes from topic A and re-produces to topic B, preserving the original message key and headers. Useful for local integration testing without a real downstream service.

Source & Issues

github.com/Asher-P/messagehook-testkit

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 38 5/14/2026