API reference — Transports

Nuvora.Nexus.Relay.Messaging.InMemory

In-memory message transport for Nuvora Nexus Relay. A drop-in replacement for the RabbitMQ transport that runs the full outbox -> broker -> inbox loop in-process, for fast infrastructure-free tests and local development.

dotnet add package Nuvora.Nexus.Relay.Messaging.InMemory

Nuvora.Nexus.Relay.Messaging.InMemory

InMemoryDeadLetterQueueReplayer

public sealed class InMemoryDeadLetterQueueReplayer : IDeadLetterQueueReplayer

IDeadLetterQueueReplayer over the in-process transport — moves messages from a queue’s dead-letter store back onto the queue with a fresh delivery-attempt budget.

Constructors

InMemoryDeadLetterQueueReplayer(InMemoryTransport transport)

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.

InMemoryMessageBroker

public sealed class InMemoryMessageBroker : IMessageBroker

IMessageBroker over the in-process InMemoryTransport. Publish routes to every bound queue and throws UnroutableMessageException when nothing matches, matching the RabbitMQ broker’s mandatory-publish behaviour the outbox relies on.

Constructors

InMemoryMessageBroker(InMemoryTransport transport)

Methods

Task DrainAsync(CancellationToken cancellationToken = default(CancellationToken))

Deterministic delivery for tests: drains every subscribed queue to completion (including redeliveries and dead-lettering). Only meaningful with InMemoryTransportOptions.DeterministicDelivery enabled.

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

bool Ping()

Health probe — the in-memory transport is reachable while it has not been disposed.

InMemoryMessageConsumer

public sealed class InMemoryMessageConsumer : IMessageConsumer, IMessageConsumerLifecycle

IMessageConsumer over the in-process InMemoryTransport. Manual-ack semantics (the message is dropped only after the handler succeeds; on failure it is redelivered with an incremented x-relay-delivery-attempts header and dead-lettered at the cap). Implements IMessageConsumerLifecycle so the inbox can observe a dropped subscription and resubscribe.

Constructors

InMemoryMessageConsumer(InMemoryTransport transport)

Properties

Task SubscriptionClosed { get; }

Completes when the active subscription is dropped. Re-armed on each InMemoryMessageConsumer.SubscribeAsync (the task instance is replaced), mirroring the RabbitMQ consumer’s lifecycle contract.

Methods

Task SubscribeAsync(string queueName, IReadOnlyCollection<string> routingKeys, Func<MessageBrokerMessage, CancellationToken, Task> handler, CancellationToken cancellationToken = default(CancellationToken))
void SimulateTransportDrop()

Test hook: simulate transport death (channel shutdown / broker-cancelled consumer) so callers exercise their resubscribe path. Completes InMemoryMessageConsumer.SubscriptionClosed.

InMemorySubscription

public sealed class InMemorySubscription

One active subscription to a queue: the handler, the delivery-attempt cap, a cancellation source that ends the delivery loop, and a task that completes when the subscription closes (so the hosting InboxProcessor can observe transport death and resubscribe).

Properties

Task Closed { get; }

Completes when this subscription stops delivering (dropped, replaced, or disposed).

string QueueName { get; }

InMemoryTransport

public sealed class InMemoryTransport : IDisposable

In-process emulation of a topic-exchange broker. Owns the queues, their routing bindings, and the per-subscription delivery loops. Both InMemoryMessageBroker and InMemoryMessageConsumer share a single instance (registered as a singleton) so a publish on the broker is delivered to the consumer’s subscription, exactly like a real transport.

Constructors

InMemoryTransport(IOptions<InMemoryTransportOptions> options, ILogger<InMemoryTransport> logger)

Properties

bool IsRunning { get; }

True while the transport is running (used by the health check / ping).

Methods

InMemorySubscription Subscribe(string queueName, IReadOnlyCollection<string> routingKeys, Func<MessageBrokerMessage, CancellationToken, Task> handler)

Declares queueName, binds it to routingKeys (empty ⇒ bind all, #) and installs handler as the active subscription. Any previous subscription on the same queue is closed first. Returns the subscription whose InMemorySubscription.Closed task the consumer surfaces as IMessageConsumerLifecycle.SubscriptionClosed.

Task DrainAsync(CancellationToken cancellationToken)

Deterministic delivery: processes every queued message on every subscribed queue to completion (including redeliveries and dead-lettering) on the caller’s thread. Used by tests with InMemoryTransportOptions.DeterministicDelivery enabled — no sleeps or polling.

Task PublishAsync(MessageBrokerMessage message, CancellationToken cancellationToken)

Routes a message to every queue whose bindings match its routing key. Throws UnroutableMessageException when no binding matches (mandatory-publish parity).

Task<int> ReplayDeadLettersAsync(string queueName, int maxMessages, CancellationToken cancellationToken)

Moves up to maxMessages messages from queueName’s dead-letter store back onto the queue with their delivery-attempt budget reset.

int DeadLetterCount(string queueName)

Test/diagnostic hook: count of dead letters held for a queue.

void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

InMemoryTransportOptions

public sealed class InMemoryTransportOptions : MessageBrokerOptions

Options for the in-memory transport. Inherits the shared broker knobs (MessageBrokerOptions.TopicPrefix, MessageBrokerOptions.AutoCreateTopics) and adds in-memory-specific settings.

Properties

bool DeterministicDelivery { get; set; }

When true, deliveries are not pumped automatically by a background loop; tests drive delivery deterministically by calling InMemoryMessageBroker.DrainAsync. This makes integration-style tests free of sleeps/polling. Default false (messages are delivered as they are published, like a real broker).

int MaxDeliveryAttempts { get; set; }

Maximum delivery attempts before a message is routed to the queue’s dead-letter queue ({queue}.dlq). Mirrors RabbitMqOptions.MaxDeliveryAttempts.

int QueueCapacity { get; set; }

Bounded capacity per queue. Publishing waits (applying back-pressure) when a queue is full rather than growing memory without limit.

Nuvora.Nexus.Relay.Messaging.InMemory.DependencyInjection

InMemoryTransportServiceCollectionExtensions

public static class InMemoryTransportServiceCollectionExtensions

Methods

static IServiceCollection AddRelayInMemoryTransport(this IServiceCollection services, Action<InMemoryTransportOptions>? configure = null)

Registers the in-memory transport: IMessageBroker, IMessageConsumer (+ IMessageConsumerLifecycle) and IDeadLetterQueueReplayer, all singletons sharing one InMemoryTransport. Interchangeable with AddRelayRabbitMq — the outbox/inbox processors work unchanged. Intended for tests and local development, not cross-process production messaging.

Nuvora.Nexus.Relay.Messaging.InMemory.HealthChecks

InMemoryTransportHealthCheck

public sealed class InMemoryTransportHealthCheck : IHealthCheck

Readiness check for the in-memory transport (parity with the RabbitMQ health check). Reports healthy while the transport has not been disposed.

Constructors

InMemoryTransportHealthCheck(InMemoryMessageBroker broker)

Methods

Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default(CancellationToken))

Runs the health check, returning the status of the component being checked.

InMemoryTransportHealthCheckBuilderExtensions

public static class InMemoryTransportHealthCheckBuilderExtensions

Methods

static IHealthChecksBuilder AddRelayInMemoryTransport(this IHealthChecksBuilder builder, string name = "relay-inmemory-transport", IEnumerable<string>? tags = null)

Adds a readiness check for the in-memory transport.