LiteBus
CatalogTransport

In-Memory Transport

  • ID: transport.inmemory
  • Name: In-memory transport
  • Maturity: GA
  • Summary: In-process channel broker used for fast tests and local workflows while preserving transport contracts.

What It Does

InMemoryTransportModule registers InMemoryTransportBroker, InMemoryPublisher, and InMemoryConsumer. Messages are queued by destination inside process memory and delivered through the same TransportMessage contract used by external brokers.

Each destination admits at most InMemoryTransportOptions.DestinationCapacity unsettled deliveries, including queued and currently handled messages. The default is 1024. When the limit is reached, PublishAsync waits asynchronously until a delivery settles or the caller cancels. LiteBus uses the lossless BoundedChannelFullMode.Wait behavior documented in the current .NET channels guidance.

Ack behavior is explicit. AcceptAsync and DiscardAsync release the delivery's capacity reservation. ReturnToQueueAsync re-enqueues with Redelivered = true and retains the reservation, so a waiting publisher cannot take the only slot and deadlock redelivery.

bus.AddInMemoryTransport(new InMemoryTransportOptions
{
    DestinationCapacity = 256
});

Public Surface

APIRole
InMemoryTransportOptions.DestinationCapacityPer-destination queued and in-flight bound
InMemoryTransportModuleRegisters in-memory transport services
InMemoryTransportBrokerQueue registry keyed by destination
InMemoryPublisher.PublishAsyncEnqueue publish request body and headers
InMemoryConsumer.StartAsyncDequeue and invoke handler loop
InMemoryDestinationEndpointDestination queue and synchronization
InMemoryPendingDeliveryDelivery snapshot with redelivery bit
LiteBusInMemoryTelemetry.MeterNameReserved in-memory adapter meter

Packages

  • LiteBus.Transport.InMemory

Requires

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

Invariants

  • Transport is process-local and not durable.
  • Destination capacity is positive, applies independently to every destination, and is validated during composition.
  • Full destinations wait for capacity; the transport does not drop old or new writes.
  • Redelivery requires explicit ReturnToQueueAsync or exception path through invoker behavior.
  • Shared transport metrics are tagged inmemory.

Non-Goals

  • Cross-process messaging.
  • Durability and replay across restart.
  • Replacing external brokers for production workloads.

Observability

Metrics

ItemValue
Shared meterLiteBus.Transport
Broker taglitebus.transport.broker="inmemory"
Shared gaugeslitebus.transport.circuit_breaker.open, litebus.transport.circuit_breaker.failure_count
Reserved adapter meterLiteBus.Transport.InMemory
OpenTelemetry registrationAddLiteBusTransportMetrics()

Tracing

  • Activity source LiteBus.Transport
  • Spans send {destination} and process {destination} with messaging.system=litebus_in_memory

Test Coverage

Covered

Test methodProject
PublishAndConsume_ShouldDeliverMessageToConsumerLiteBus.Transport.UnitTests (InMemory/)
ReturnToQueue_ShouldRedeliverMessageLiteBus.Transport.UnitTests (InMemory/)
HandlerThrow_ShouldRequeueMessageByDefaultLiteBus.Transport.UnitTests (InMemory/)
PublishAsync_WhenDestinationIsFull_ShouldWaitForSettlementLiteBus.Transport.UnitTests (InMemory/)
PublishAsync_WhenCapacityWaitIsCanceled_ShouldReleaseAdmissionWaiterLiteBus.Transport.UnitTests (InMemory/)
Constructor_WithNonPositiveDestinationCapacity_ShouldThrowLiteBus.Transport.UnitTests (InMemory/)
PublishThroughInMemoryTransport_ShouldAcceptProcessAndDispatchCommandLiteBus.Durable.IntegrationTests (Ingress/InMemory/)
ProcessPendingAsync_ShouldPublishEnvelopeToInMemoryDestinationLiteBus.Durable.IntegrationTests (Dispatch/Outbox/InMemory/)
ProcessPendingAsync_ShouldPublishLeasedEnvelopeToInMemoryDestinationLiteBus.Durable.IntegrationTests (Dispatch/Inbox/InMemory/)

Untested

  • Gauge export assertions with broker tag inmemory.
  • Circuit-breaker-open behavior in a forced-failure in-memory path.

Out-of-Scope

  • Cross-process transport behavior.
  • Persistence and restart recovery.

Deep Docs

On this page