LiteBus
CatalogTransport

Kafka Transport

  • ID: transport.kafka
  • Name: Kafka transport
  • Maturity: GA
  • Summary: Kafka adapter built on Confluent.Kafka with manual offset commit and seek-based redelivery.

What It Does

KafkaTransportModule registers KafkaPublisher and KafkaConsumer behind transport contracts. Publish maps Destination to topic and Route to record key. Consume disables auto-commit and only commits on AcceptAsync.

When handlers call ReturnToQueueAsync, the adapter seeks to the consumed offset and applies configurable exponential backoff via KafkaSeekBackoff.

Public Surface

Registration and Runtime Types

APIRole
KafkaTransportModuleRegisters Kafka publisher and consumer
KafkaPublisher.PublishAsyncProduces one Kafka record
KafkaConsumer.StartAsyncRuns consume loop with manual commit
KafkaMessageMapperMaps TransportPublishRequest and consumed records
KafkaSeekBackoffTracks per-offset retry delay
KafkaConnectivityDiagnosticCheckDescribes the cluster for host readiness
LiteBusTransportKafkaTelemetry.MeterNameReserved Kafka meter name

Options

PropertyDefaultPurpose
BootstrapServersrequiredKafka bootstrap server list
ClientIdnullProducer and consumer client id
ConsumerGroupIdlitebus-transportKafka consumer group
MessageTimeoutMsnullProducer message timeout
ConnectivityCheckTimeout5sCluster description request timeout
SeekFailureBackoffInitial250msInitial seek retry delay
SeekFailureBackoffMax30sMax seek retry delay
SeekFailureBackoffMultiplier2.0Exponential backoff multiplier

Ack Mapping

Transport callKafka action
AcceptAsyncCommit consumed offset
DiscardAsyncCommit consumed offset
ReturnToQueueAsyncSeek to consumed offset (do not commit)

Packages

  • LiteBus.Transport.Kafka

Requires

  • transport.publish-consume-contracts
  • transport.manual-acknowledgement
  • transport.single-broker-registration

Invariants

  • Consumer auto-commit is disabled.
  • Offset progression happens only through explicit ack delegates.
  • Ordering guarantee is partition-scoped, not topic-scoped.

Non-Goals

  • Exactly-once transaction support.
  • Topic provisioning and ACL management.
  • Multi-broker compose in one process.

Observability

Metrics

ItemValue
Shared meterLiteBus.Transport
Broker taglitebus.transport.broker="kafka"
Shared gaugeslitebus.transport.circuit_breaker.open, litebus.transport.circuit_breaker.failure_count
Reserved adapter meterLiteBus.Transport.Kafka (LiteBusTransportKafkaTelemetry.MeterName)
OpenTelemetry registrationAddLiteBusTransportMetrics()

Tracing

  • Activity source LiteBus.Transport with send {destination} and process {destination} spans.
  • Consume spans include destination, key, message id, and correlation id when present.

Diagnostics

  • Diagnostic check id: transport.kafka.connectivity
  • DescribeClusterAsync must return at least one broker within ConnectivityCheckTimeout.
  • Provider exception text is not returned. Caller cancellation propagates to the host runner.

Test Coverage

Covered

Test methodProject
Build_ShouldRegisterTransportServicesLiteBus.Transport.UnitTests (Kafka/)
Build_SecondTransportModule_ShouldThrowLiteBus.Transport.UnitTests (Kafka/)
CheckAsync_WhenClusterIsUnavailable_ShouldReturnUnhealthyLiteBus.Transport.UnitTests (Kafka/)
CheckAsync_WhenCallerCancels_ShouldPropagateCancellationLiteBus.Transport.UnitTests (Kafka/)
ToKafkaMessage_ShouldMapKeyBodyAndHeadersLiteBus.Transport.UnitTests (Kafka/)
ToTransportMessage_ShouldExposeCommitDelegateLiteBus.Transport.UnitTests (Kafka/)
ToTransportMessage_ReturnToQueueAsync_ShouldSeekToConsumedOffsetLiteBus.Transport.UnitTests (Kafka/)
RecordSeek_repeatedFailures_ShouldIncreaseBackoffLiteBus.Transport.UnitTests (Kafka/)
PublishThroughKafka_ShouldAcceptProcessAndDispatchCommandLiteBus.Durable.IntegrationTests (Ingress/Kafka/)
PublishThroughKafka_ShouldAcceptProcessAndDispatchCommand readiness assertionLiteBus.Durable.IntegrationTests (Ingress/Kafka/)
TransientAcceptFailure_ShouldRedeliverSameOffsetWithoutRestartLiteBus.Durable.IntegrationTests (Ingress/Kafka/)
ProcessPendingAsync_ShouldPublishEnvelopeToKafkaTopicLiteBus.Durable.IntegrationTests (Dispatch/Outbox/Kafka/)
ProcessPendingAsync_WhenCircuitBreakerOpen_ShouldNotPublishLiteBus.Durable.IntegrationTests (Dispatch/Outbox/Kafka/)

Untested

  • Raw KafkaPublisher and KafkaConsumer against a live broker outside durable wrappers.
  • Exported gauge assertions for broker tag kafka.
  • Broker integration assertions for exported Kafka activities.

Out-of-Scope

  • Exactly-once Kafka transactions.
  • Automatic topic creation policy for production.

Deep Docs

On this page