LiteBus
CatalogTransport

Publish and Consume Contracts

  • ID: transport.publish-consume-contracts
  • Name: Publish and consume contracts
  • Maturity: GA
  • Summary: Broker-neutral API contract for publishing messages and running consumer loops.

What It Does

Transport adapters implement:

  • ITransportPublisher for outbound publish via TransportPublishRequest
  • IMessageConsumer for inbound consume loops via TransportConsumerOptions and TransportMessage handlers

These abstractions isolate dispatch and ingress from broker SDK APIs.

Public Surface

Core Contracts

TypeMemberRole
ITransportPublisherPublishAsync(TransportPublishRequest, CancellationToken)Publish one message
IMessageConsumerStartAsync(TransportConsumerOptions, handler, CancellationToken)Start consume loop
IMessageConsumerStopAsync(CancellationToken)Request stop
IMessageConsumerWaitUntilStoppedAsync(CancellationToken)Await full shutdown
IMessageConsumerIAsyncDisposableAsync release

Publish Request Model

PropertyTypePurpose
DestinationstringBroker destination target
Routestring?Broker route key or topic hint
BodyReadOnlyMemory<byte>Payload bytes
HeadersIReadOnlyDictionary<string, object?>?Application headers
ContentTypestring?Content type hint
PersistentboolPublish durability hint
MandatoryboolMandatory delivery hint
MessageIdstring?Message id property
CorrelationIdstring?Correlation id property

Consumer Options Model

PropertyTypePurpose
DestinationstringQueue, topic, or destination name
SubscriptionNamestring?Named subscription for topic-based brokers
MaxInFlightMessagesintProvider-neutral cap on concurrent LiteBus handler calls, default 32
PrefetchCountintNative RabbitMQ or Azure Service Bus prefetch, default 0
ReceiveBatchSizeintMessages requested per SQS receive call, default 1 and valid from 1 through 10
MaxConcurrentCallsint?Native Azure Service Bus callback concurrency
DeclareDestinationboolDeclare destination before consume
DurableDestinationboolDurable destination declaration
DestinationArgumentsIReadOnlyDictionary<string, object?>?Broker-specific destination args

MaxInFlightMessages has one meaning across every adapter: no more than that number of LiteBus delivery handlers execute concurrently for one subscription. Native broker controls remain separate because they regulate different resources. RabbitMQ prefetch limits unacknowledged deliveries, Azure prefetch fills a local cache while MaxConcurrentCalls controls processor callbacks, and SQS ReceiveBatchSize sets ReceiveMessageRequest.MaxNumberOfMessages.

The in-memory adapter separately bounds queued and in-flight deliveries with InMemoryTransportOptions.DestinationCapacity. This is publisher backpressure, not consumer callback concurrency. A full destination waits asynchronously with BoundedChannelFullMode.Wait, and publish cancellation stops that capacity wait without dropping an admitted delivery.

The limits match the current provider contracts:

Packages

  • LiteBus.Transport.Abstractions

Requires

  • None

Invariants

  • Contracts stay broker-neutral and do not reference SDK types.
  • Handler acknowledgement remains explicit via TransportMessage methods.
  • One broker module registration per process (transport.single-broker-registration).

Non-Goals

  • Durable inbox or outbox persistence semantics.
  • Automatic message deserialization and handler binding.
  • Multi-broker transaction support.

Observability

  • Tracing uses shared source and span names (transport.tracing).
  • Circuit-breaker metrics attach at adapter modules (transport.metrics).

Test Coverage

Covered

Test methodProject
CanonicalHeaders_ShouldUseStableWireNamesLiteBus.Transport.UnitTests
PublishAsync_ThenConsume_AcknowledgesMessageLiteBus.Transport.IntegrationTests (Amqp/)
StopAsync_AfterStart_PreventsFurtherDeliveriesLiteBus.Transport.IntegrationTests (Amqp/)
PublishAndConsume_ShouldDeliverMessageToConsumerLiteBus.Transport.UnitTests (InMemory/)
PublishThroughKafka_ShouldAcceptProcessAndDispatchCommandLiteBus.Durable.IntegrationTests (Ingress/Kafka/)
PublishThroughSqs_ShouldAcceptProcessAndDispatchCommandLiteBus.Durable.IntegrationTests (Ingress/AwsSqs/)
PublishThroughServiceBus_ShouldAcceptProcessAndDispatchCommandLiteBus.Durable.IntegrationTests (Ingress/AzureServiceBus/)
CreateBoundedHandler_WithThreeConcurrentCalls_ShouldAdmitConfiguredMaximumLiteBus.Transport.UnitTests
InboxIngressOptions_ShouldPreserveSafetyAndNativeConsumerSettingsLiteBus.Durable.IntegrationTests (Registration/)

Untested

  • WaitUntilStoppedAsync semantics across all adapters.
  • IAsyncDisposable behavior after partial startup failure.
  • Adapter-level behavior for Mandatory and Persistent hints.

Out-of-Scope

  • Durable storage semantics.
  • Handler registration and contract resolution policy.

Deep Docs

On this page