API reference — Transports
Nuvora.Nexus.Relay.Messaging.Kafka
Apache Kafka message transport for Nuvora Nexus Relay
dotnet add package Nuvora.Nexus.Relay.Messaging.Kafka
Nuvora.Nexus.Relay.Messaging.Kafka
KafkaDeadLetterReplayer
public sealed class KafkaDeadLetterReplayer : IDeadLetterQueueReplayer
IDeadLetterQueueReplayer for Apache Kafka: reads a group’s dead-letter topic and re-produces each record to the group’s retry topic (which the group consumes) with a reset delivery budget, so it is reprocessed after the underlying defect is fixed. A dedicated, stable consumer group tracks how far the dead-letter topic has been drained, so repeated replays don’t re-emit already- replayed records. Each record is re-produced (acks=all) before its offset is committed, so a crash mid-replay duplicates rather than loses — duplicates are absorbed by the consumer’s inbox dedup.
Constructors
KafkaDeadLetterReplayer(IOptions<KafkaOptions> options, ILogger<KafkaDeadLetterReplayer> logger)
Methods
Task<int> ReplayAsync(string queueName, int maxMessages = 100, CancellationToken cancellationToken = default(CancellationToken))
Replays up to maxMessages messages from queueName’s dead-letter queue back onto queueName. Each message is re-enqueued (confirmed by the broker) before its DLQ copy is acknowledged, so a crash mid-replay duplicates rather than loses — duplicates are absorbed by the consumer’s inbox dedup. Returns the number replayed.
KafkaMessageBroker
public sealed class KafkaMessageBroker : IMessageBroker, IAsyncDisposable
IMessageBroker over Apache Kafka (Confluent.Kafka). Publishes events to a topic (the “exchange”) with the routing key as the message key and a header; produces with acks=all so a publish only completes once the partition leader and in-sync replicas have persisted the record — a failed publish throws and the outbox records it rather than silently dropping the event. There is no per-consumer “unroutable” signal (every consumer group reads the whole topic), so DetectsUnroutableMessages is false.
Constructors
KafkaMessageBroker(IOptions<KafkaOptions> options, ILogger<KafkaMessageBroker> logger)
Methods
Task PublishAsync(MessageBrokerMessage message, CancellationToken cancellationToken = default(CancellationToken))
Publish a message to the message broker
Task PublishManyAsync(IEnumerable<MessageBrokerMessage> messages, CancellationToken cancellationToken = default(CancellationToken))
Publish multiple messages to the message broker
Task<bool> PingAsync(CancellationToken cancellationToken = default(CancellationToken))
Connectivity probe for the health check: fetches cluster metadata via an admin client and confirms at least one broker is reachable. Throws if the bootstrap servers are unreachable.
ValueTask DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
KafkaMessageConsumer
public sealed class KafkaMessageConsumer : IMessageConsumer, IAsyncDisposable
IMessageConsumer over Apache Kafka (Confluent.Kafka). A Relay “queue” is a consumer group (group id = the queue name) that reads the event topic plus its own retry topic; routing keys are filtered client-side. Ack ≡ manual offset commit after the handler succeeds, so with the inbox it yields exactly-once processing on top of at-least-once delivery.
Retry / poison. Kafka has no per-message nack, dead-letter queue or delayed delivery, so a failed message is republished to the group’s retry topic (which the same group consumes) with an incremented attempt count — and, once KafkaOptions.MaxDeliveryAttempts is reached, to the group’s dead-letter topic. The original offset is committed either way so the group keeps moving (no head-of-line blocking). The registered IMessageErrorPolicy, consume filters and IConsumerRedeliveryScheduler compose as for the other transports; delayed retries need a redelivery scheduler since Kafka has no native delay.
The Kafka consumer is single-threaded, so each group runs a dedicated synchronous poll loop; the async handler is awaited inline. It does not implement IMessageConsumerLifecycle.
Constructors
KafkaMessageConsumer(IOptions<KafkaOptions> options, ILogger<KafkaMessageConsumer> logger, IMessageErrorPolicy? errorPolicy = null, IEnumerable<IConsumeFilter>? consumeFilters = null, IConsumerRedeliveryScheduler? redeliveryScheduler = null)
Methods
Task SubscribeAsync(string queueName, IReadOnlyCollection<string> routingKeys, Func<MessageBrokerMessage, CancellationToken, Task> handler, CancellationToken cancellationToken = default(CancellationToken))
ValueTask DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
KafkaOptions
public sealed class KafkaOptions : MessageBrokerOptions
Connection and topology options for the Apache Kafka transport (Confluent.Kafka client).
Kafka is a partitioned log, so the exchange/routing-key SPI maps differently: events publish to a KafkaOptions.TopicName (the “exchange”) with the routing key in a header and as the message key; a Relay “queue” is a consumer group (group id = the queue name) that independently reads the topic, with routing keys filtered client-side. Kafka has no per-message nack, dead-letter queue or delayed delivery, so failures are republished to a per-group retry topic (same group consumes it) with an incremented attempt count and, at the cap, to a per-group dead-letter topic; the original offset is committed either way so the group keeps moving. Ack ≡ offset commit.
Properties
bool ReadFromEarliest { get; set; }
Where a new consumer group starts reading when it has no committed offset.
int MaxDeliveryAttempts { get; set; }
Maximum delivery attempts before a message is routed to its dead-letter topic.
int Partitions { get; set; }
Number of partitions for auto-created topics.
int PollTimeoutMs { get; set; }
Poll timeout (milliseconds) per consume call.
short ReplicationFactor { get; set; }
Replication factor for auto-created topics (1 for a single-broker dev/test cluster).
string BootstrapServers { get; set; }
Comma-separated bootstrap servers (e.g. localhost:9092).
string TopicName { get; set; }
Topic events are published to (the “exchange”).
Nuvora.Nexus.Relay.Messaging.Kafka.DependencyInjection
KafkaServiceCollectionExtensions
public static class KafkaServiceCollectionExtensions
Registration helpers for the Apache Kafka message transport. Interchangeable with the other Relay transports — the outbox/inbox processors work unchanged.
Methods
static IServiceCollection AddRelayKafka(this IServiceCollection services, Action<KafkaOptions> configure)
Nuvora.Nexus.Relay.Messaging.Kafka.HealthChecks
KafkaHealthCheck
public sealed class KafkaHealthCheck : IHealthCheck
Health check for Apache Kafka connectivity: probes the broker with a bounded timeout, so an unreachable broker surfaces as Unhealthy instead of only as outbox publish failures.
Constructors
KafkaHealthCheck(IMessageBroker broker)
Methods
Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken))
Runs the health check, returning the status of the component being checked.
KafkaHealthCheckBuilderExtensions
public static class KafkaHealthCheckBuilderExtensions
Health-check registration for the Apache Kafka broker connection.
Methods
static IHealthChecksBuilder AddRelayKafka(this IHealthChecksBuilder builder, string name = "relay-kafka", IEnumerable<string>? tags = null)
Adds the Apache Kafka connectivity health check (5s bound). Wire it into the readiness endpoint: services.AddHealthChecks().AddRelayKafka().