Skip to main content

RabbitMQ Streams

This package is not published until it supports both send and receive (#316). Source integration and tests remain available in the repository.

Relayer.RabbitMQ.Streams manages named native StreamSystem instances and stream topology using RabbitMQ.Stream.Client 1.13.0. Relayer sending and receiving are not implemented. Declaring Send or Consume fails before connecting. Direct ITransport.SendAsync and SendBatchAsync calls also fail explicitly.

Register a connection and topology​

Enable the broker's rabbitmq_stream plugin and expose its stream protocol port, normally 5552. This package uses the stream protocol, independently of the RabbitMQ AMQP transport.

using System.Net;
using Microsoft.Extensions.Options;
using RabbitMQ.Stream.Client;
using Relayer;
using Relayer.RabbitMQ.Streams;
using Relayer.Transports;

services.AddRelayer(relayer => relayer.RabbitMQStreams("events", streams =>
{
streams.TopologyMode = TopologyMode.Provision;
streams.Options.Configure(options =>
{
options.Configuration = new StreamSystemConfig
{
Endpoints = [new DnsEndPoint("localhost", 5552)],
UserName = "app",
Password = "configured-secret",
};
options.Streams.Add(new("orders")
{
Configuration = new StreamSpec("orders")
{
MaxAge = TimeSpan.FromDays(7),
},
});
});
}));

Configuration is the native StreamSystemConfig instance, passed unchanged. Native authentication, TLS, endpoint resolution, connection pools and locator recovery remain native behavior. DI resolution does not connect. Startup creates the owned system and checks native server properties. Shutdown and disposal close only that named system; externally created systems remain caller-owned and cannot be supplied to this registration.

With application logging configured, the native client logs failed connection attempts, including the endpoint and exception, under the RabbitMQ.Stream.Client.StreamSystem category.

Native operations do not accept a CancellationToken. Startup and topology check cancellation around native calls and let in-flight calls finish according to native connection and RPC timeouts. Set native timeouts for the deployment. Relayer never abandons a pending connection task.

Shutdown closes the owned system when no lifecycle or topology operation holds it, even if the host shutdown token has already expired. If another operation holds the system, shutdown honors cancellation while waiting for access. Once shutdown starts the native close, it awaits completion. Disposal waits for access and closes the system if it is still open.

Topology modes​

None performs no topology requests. Host startup still opens its native system. Validate, the default, uses native StreamExists without creating a producer, consumer or probe message. Name-only declarations check existence:

options.Streams.Add(new("orders"));

The stream protocol does not expose retention/configuration readback through this client. In Validate mode, a declaration with Configuration reports that configuration equivalence cannot be checked and fails startup, even when the stream exists. Use a name-only declaration when existence is the intended assertion.

Provision passes each supplied StreamSpec unchanged to native CreateStream. Its name must match the declaration. The broker enforces native argument equivalence for existing streams; conflicts appear in the topology report. Relayer continues with unrelated declarations and never calls update, delete or purge operations. Name-only declarations still check existence and do not create missing streams.

Super streams​

Add a native PartitionsSuperStreamSpec or BindingsSuperStreamSpec to provision a super stream on RabbitMQ 3.13 or later:

options.SuperStreams.Add(new("events")
{
Configuration = new PartitionsSuperStreamSpec("events", 3)
{
MaxAge = TimeSpan.FromDays(7),
},
});

Provision forwards the specification unchanged to native CreateSuperStream. If the name already exists, RabbitMQ can return success without comparing the requested partition count, binding keys or settings. Relayer verifies that native partition lookup returns at least one stream. Manage changes and verify existing settings externally.

In Provision, name-only stream checks run after super-stream provisioning. You can declare a partition as a name-only stream and provision its super stream in the same startup. If the native client rejects a super-stream specification, the topology report names the declaration and includes the native validation error. Provisioning continues with the other declarations.

A name-only declaration (options.SuperStreams.Add(new("events"))) checks for native partitions in either Validate or Provision. In Validate, a declaration with Configuration fails because the native API cannot verify configuration equivalence. An ordinary exchange without stream partitions fails both modes.

Stream and super-stream declarations manage topology only. Relayer receivers remain planned.

Message execution status​

Message execution is tracked in #316. RabbitMQ.Stream.Client 1.13.0 supplies ConsumerConfig.SubscriptionListener, which can override the starting offset on each subscription, including reconnects and super-stream partitions. By default, the reliable consumer resumes after the last consumed offset. The planned receive path must resume from durable settlement so a failed handler or dead-letter write can be retried after reconnect. If the listener throws, the native client keeps its default offset, so recovery must handle offset lookup failures before returning from the listener.

RabbitMQ.Stream.Client 1.13.0 can return from Consumer.Close() while a message handler is running. The consumer connection can then reject the handler's checkpoint. The client maintainer closed the upstream report after demonstrating a checkpoint through the locator.

With the StreamSystem still open, call StoreOffset(reference, stream, offset) on that system after consumer close. For a super stream, pass the partition stream name supplied to the message handler. This works on RabbitMQ 4.1.4 with client 1.13.0. The caller still owns callback completion and must keep the locator open through the final checkpoint. Relayer tracks the remaining graceful shutdown requirement in #316.

To use the available connection and topology support, omit send routes and consumers from the RabbitMQ Streams registration.

Streams use log offsets, not per-message acknowledgement, requeue or native dead-letter settlement. This foundation advertises no scheduling, redelivery, dead-letter, ordering-by-key, replay or transaction support. Future execution must validate supported guarantees at startup and use the existing core pipelines and durable failure handling.

Real-broker topology, lifecycle and locator recovery tests cover this foundation. Native AOT smoke coverage checks registration and native message serialization. Transport conformance, creation-context propagation and native-versus-Relayer message benchmarks remain required for future execution; this foundation makes no message-path performance or delivery-guarantee claim.