MessageHook.Kafka
1.0.0
dotnet add package MessageHook.Kafka --version 1.0.0
NuGet\Install-Package MessageHook.Kafka -Version 1.0.0
<PackageReference Include="MessageHook.Kafka" Version="1.0.0" />
<PackageVersion Include="MessageHook.Kafka" Version="1.0.0" />
<PackageReference Include="MessageHook.Kafka" />
paket add MessageHook.Kafka --version 1.0.0
#r "nuget: MessageHook.Kafka, 1.0.0"
#:package MessageHook.Kafka@1.0.0
#addin nuget:?package=MessageHook.Kafka&version=1.0.0
#tool nuget:?package=MessageHook.Kafka&version=1.0.0
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.Kafkaautomatically pullsMessageHook.OrchestrationandMessageHook.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
| Product | Versions 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. |
-
net9.0
- KafkaFlow (>= 4.0.0)
- KafkaFlow.Extensions.Hosting (>= 4.0.0)
- KafkaFlow.Serializer.Json (>= 1.5.8)
- MessageHook.Orchestration (>= 1.0.0)
- protobuf-net (>= 3.2.30)
- protobuf-net.Core (>= 3.2.30)
- Utf8Json (>= 1.3.7)
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 |