Path: redb-route/redb.Route.Kafka/KafkaEndpoint.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Kafka/KafkaEndpoint.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Kafka;
///
/// Kafka endpoint. The topic name comes from .
/// Supports both producing and consuming with full transactional semantics.
///
public sealed class KafkaEndpoint : EndpointBase
{
/// Kafka topic name (from URI path).
public string TopicName { get; }
/// Resolved connection factory from the registry (null if not configured).
internal KafkaConnectionFactory? ResolvedFactory { get; }
/// Creates a Kafka endpoint. The factory is resolved by the component
/// BEFORE options validation (it may be the only source of the brokers).
public KafkaEndpoint(EndpointUri uri, KafkaComponent component, KafkaEndpointOptions options,
KafkaConnectionFactory? resolvedFactory = null)
: base(uri, component, options)
{
TopicName = uri.Path;
ResolvedFactory = resolvedFactory;
_headerFilter = new redb.Route.Core.EndpointHeaderFilter(this, options.HeaderFilterStrategy);
}
private readonly redb.Route.Core.EndpointHeaderFilter _headerFilter;
///
/// The header filter strategy of this endpoint: the one headerFilterStrategy=#name names, or
/// . A name the registry does not hold fails when the producer or
/// consumer is built.
///
internal redb.Route.Abstractions.IHeaderFilterStrategy HeaderFilterStrategy => _headerFilter.Or(KafkaHeaderFilterStrategy.Default);
///
public override IProducer CreateProducer()
{
// One name for each thing: a producer's partition is Camel's partitionKey; partitionNumber is a consumer's.
if (Options.PartitionNumber.HasValue)
throw new ArgumentException(
"Kafka producer: 'partitionNumber' names the partition a consumer reads. The partition a producer sends to " +
$"is 'partitionKey' (Apache Camel's name), or the {KafkaHeaders.PartitionKey} header per message.",
nameof(KafkaEndpointOptions.PartitionNumber));
return new KafkaProducer(this, Options);
}
///
public override IConsumer CreateConsumer(IProcessor processor)
{
if (Options.PartitionKey.HasValue)
throw new ArgumentException(
"Kafka consumer: 'partitionKey' names the partition a producer sends to. The partition a consumer reads is " +
"'partitionNumber'.", nameof(KafkaEndpointOptions.PartitionKey));
if (string.IsNullOrWhiteSpace(Options.GroupId))
throw new InvalidOperationException(
$"The 'groupId' parameter is required for Kafka consumer on topic '{TopicName}'.");
return new KafkaConsumer(this, processor, Options);
}
}