redb.Route.RabbitMQ 4.8.0

Prefix Reserved
dotnet add package redb.Route.RabbitMQ --version 4.8.0
                    
NuGet\Install-Package redb.Route.RabbitMQ -Version 4.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="redb.Route.RabbitMQ" Version="4.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="redb.Route.RabbitMQ" Version="4.8.0" />
                    
Directory.Packages.props
<PackageReference Include="redb.Route.RabbitMQ" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add redb.Route.RabbitMQ --version 4.8.0
                    
#r "nuget: redb.Route.RabbitMQ, 4.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package redb.Route.RabbitMQ@4.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=redb.Route.RabbitMQ&version=4.8.0
                    
Install as a Cake Addin
#tool nuget:?package=redb.Route.RabbitMQ&version=4.8.0
                    
Install as a Cake Tool

redb.Route.RabbitMQ

RabbitMQ transport for redb.Route. Consumer and producer with exchanges, queues, dead-letter, priority, TTL, and the official RabbitMQ.Client 7.x.

NuGet License: Apache 2.0

Installation

dotnet add package redb.Route.RabbitMQ

Usage

URI Format

rabbitmq://queue-name?host=localhost&exchange=my-exchange&routingKey=order.*

Fluent DSL

using redb.Route.RabbitMQ;

// Consumer with exchange binding
From(Rabbit.Queue("orders")
        .Host("rabbitmq.local")
        .Username("guest").Password("guest")
        .Exchange("order-exchange", "topic")
        .RoutingKey("order.new")
        .PrefetchCount(50)
        .ConcurrentConsumers(4))
    .Log("Order received")
    .To("direct://process");

// Producer with dead-letter
From("direct://outbound")
    .To(Rabbit.Queue("events")
        .Host("rabbitmq.local")
        .Durable()
        .MessageTtl(86400000)
        .DeadLetterExchange("dlx")
        .DeadLetterRoutingKey("failed"));

An exchange without a queue name

Rabbit.Exchange(name, type) builds an endpoint with no queue name (rabbitmq:?exchange=...). A producer publishes to the exchange; a consumer reads a temporary queue of its own (exclusive, auto-delete) that the broker names and that is bound to the exchange, so every instance of a fanout consumer gets its copy of each message. The consumer needs .Declare(): without it nothing creates and binds the temporary queue, and it fails at start.

// Every instance of the application gets each notification
From(Rabbit.Exchange("ui-notify", "fanout").ConnectionFactory("rabbit").Declare())
    .To("direct://push-to-browsers");

From("direct://notify")
    .To(Rabbit.Exchange("ui-notify", "fanout").ConnectionFactory("rabbit").Declare());

Rabbit.Queue("") is refused and names Rabbit.Exchange: an empty queue name is a different endpoint, not a queue.

Fluent Builder API

Category Methods
Connection .Host(), .Port(), .Username(), .Password(), .VirtualHost(), .ConnectionFactory(), .ClientName(), .PublisherConnection()
TLS and login .Ssl(serverName, certPath, certPassphrase), .SslCaCertPath(), .SslProtocols(), .RevocationMode(mode, softFail), .AuthMechanism()
Recovery .AutomaticRecovery(), .TopologyRecoveryEnabled(), .RecoveryInterval(), .Heartbeat(), .ConnectionTimeout()
Exchange .Exchange(name, type?), .ExchangeDurable(), .ExchangeAutoDelete(), .Declare()
Queue .Durable(), .AutoDelete(), .Exclusive(), .RoutingKey(), .MaxLength(), .MaxLengthBytes(), .Overflow(), .QueueType(), .MaxPriority()
Consumer .ConcurrentConsumers(), .PrefetchCount(), .AckMode(), .MaximumRetryAttempts(), .RetryDelay(), .RejectAndDontRequeue(), .DisableReplyTo(), .Batching(), .MaxBatchMessages(), .PollTimeoutMs(), .BatchingIntervalMs(), .Transacted(), .Mandatory(), .ReplyTo(), .PreserveMessageQos(), .Timeout()
Message .ContentType(), .MessageTtl(), .Expires()
DLX .DeadLetterExchange(), .DeadLetterRoutingKey()

Most builder methods accept both constant values and IExpression for runtime resolution via the expression engine.

Queues are durable by default, and a consumer without a queue name gets an exclusive temporary queue. A named queue with durable=false must also be exclusive=true on RabbitMQ 4.3 and later: the broker refuses transient non-exclusive queues there (541 INTERNAL_ERROR, transient_nonexcl_queues) unless its configuration permits that deprecated feature.

Consumer concurrency & acknowledgement

  • .ConcurrentConsumers(N) is the single knob for consumer-side parallelism: it sets both the channel's AMQP consumer-dispatch concurrency and the app-level concurrency semaphore, so up to N messages from the queue are processed concurrently. Default 1 (strictly serial — message order preserved). With N > 1, ordering is not preserved and your processor must be thread-safe. Keep .PrefetchCount() ≥ N so the broker keeps the parallel slots fed.
  • .AckMode(AckMode.Auto) (ackMode=auto) switches the consumer to broker-side auto-acknowledge (at-most-once): the broker settles each delivery on hand-off, so a failed turn does not requeue. Default ackMode=manual (at-least-once: ack after a successful turn; a failed one is settled as in A failed message). ackMode=auto cannot be combined with .Transacted(). The same option on every broker consumer.

A failed message

As in Apache Camel's spring-rabbitmq, a delivery on which the route fails is tried again in the consumer: maximumRetryAttempts attempts in all, the first included (default 5), retryDelay milliseconds apart (default 1000), each on a fresh exchange. A delivery that failed every attempt is then rejected without requeue (rejectAndDontRequeue=true, the default): the broker hands it to the queue's dead letter exchange when one is configured (deadLetterExchange and deadLetterRoutingKey with declare=true, or x-dead-letter-exchange on the queue), and drops it otherwise. rejectAndDontRequeue=false nacks it with requeue instead: the broker delivers it again and the attempts start over. A route error handler that handles the failure (OnException(...).Handled(true), a dead letter channel) ends the attempts at once: the delivery is acknowledged. The consumer's own stop is not a failure: a delivery interrupted by it is requeued.

Batch mode

batching=true makes the consumer hand the route one exchange per batch of deliveries, by the batch contract every broker of redb.Route follows:

  • maxBatchMessages caps the batch (default and maximum: prefetchCount, as the broker never hands over more unacknowledged deliveries); pollTimeoutMs (default 1000) sends a batch on once no delivery came for that long, restarted by every delivery; batchingIntervalMs sends it on once that long has passed since its first delivery. A batch option without batching=true, a value out of range, maxBatchMessages above prefetchCount and batching=true with replyTo=true fail the start.
  • The body is a List<IMessage>, one message per delivery with its own body, headers and redbRmq.* metadata, even for a batch of one; the size is body.Count. redbRmq.Exchange and redbRmq.RoutingKey are set on the batch message when every delivery agrees. The exchange is InOnly. Split over the body gives each part its delivery.
  • concurrentConsumers workers each collect and run one batch at a time; the deliveries the broker hands over (prefetchCount at most) are shared among them.
  • Every delivery of the batch is acknowledged after the route. A failed batch follows the rule of a failed delivery for every delivery in it: the batch is run again up to maximumRetryAttempts, retryDelay apart, then every delivery is rejected without requeue, to the dead letter exchange (rejectAndDontRequeue=false: requeued).
  • A delivery with a reply-to cannot be answered from a one-way batch: it is not put into the batch but rejected at once without requeue, with an error in the log and the endpoint statistics. disableReplyTo=true (Apache Camel's name, single mode too) ignores senders' reply-to: such deliveries are batched and nobody replies.
  • A batch half collected when the consumer stops is not run: its deliveries are requeued, as are those still waiting.

A list body

A list of IMessage (a batch consumer's body, for one) is sent element by element: each element is its own message with its own body and headers, none of the exchange's, routed by the endpoint's options resolved on that element. Each is this producer's single send, so a failure stops the list and the messages before it stay. A plain list (one whose text would be its type name) is refused, and so is any list at a request-reply producer (replyTo=true): split it.

Transactions

  • Consumer. .Transacted() takes deliveries on a transacted channel: every ack, and every reject or nack of a failed delivery, is followed by tx.commit, so the broker has applied it before the next delivery is settled. The acknowledgement belongs to the consumer, not to the route's .Transacted() block: it comes last, after the database and the deferred sends have committed. This works with concurrentConsumers above 1 as well.
  • Producer. Inside a route's .Transacted() block a publish joins the transaction: it goes out once the database has committed and is dropped if the block rolls back. .Transacted(false) publishes at once, outside the transaction; .Transacted() requires an enclosing block and fails the step outside one. A request-reply producer (.ReplyTo()) always publishes at once and refuses .Transacted(): a request held back until the commit would wait for a reply that cannot come.
  • Several publishes in one block. The deferred publishes of one producer in a block are committed in one channel transaction, on a channel of the producer's own (a channel with publisher confirms cannot run transactions): they arrive together, in order, or not at all. The producer's batches take turns on that channel, and a channel transaction is markedly slower than publisher confirms.

See the framework-wide Transactions guide (TRANSACTIONS.md in the redb.Route repository).

Headers

Exchange headers become AMQP headers of a published message and of an RPC reply, and the AMQP headers of a delivery or an RPC reply come back as exchange headers. A header named after a basic property (MessageId, CorrelationId, ReplyTo...) goes into that property instead; redbRmq.* headers are exchange metadata and stay back.

The reply-to of a delivery is not carried on: an ordinary (not request-reply) send leaves the ReplyTo header out, so a message consumed with a sender's reply-to and forwarded here does not make another consumer answer into a queue of another system, as in Apache Camel's JMS. preserveMessageQos=true (.PreserveMessageQos()) keeps it, for a bridge that needs it or a route that names a reply address on an ordinary send. The correlation id is always carried; a request-reply send (replyTo=true) sets its own reply-to.

headerFilterStrategy=#name names an IHeaderFilterStrategy in the registry that decides which headers the endpoint carries, as in Apache Camel: outgoing for a published request and a consumer's RPC reply, incoming for a delivery and the reply a request-reply producer receives. It replaces the default, RabbitMQHeaderFilterStrategy, entirely; derive from that class to add to it. The basic properties and the consumer's redbRmq.* metadata are set whatever the strategy says.

ctx.AddToRegistry("correlationOnly", new DefaultHeaderFilterStrategy
{
    OutFilter = ["Correlation-ID"],
    FilterOnMatch = false,   // a whitelist: only the listed headers go out
});
// rabbitmq://orders?host=localhost&headerFilterStrategy=#correlationOnly

Part of

redb.Route — ESB & EIP Framework for .NET

Named connection factory

Keep credentials out of the route URI: register a factory in the context registry and reference it by name. A set-but-unknown name fails loud at startup — a typo can never silently fall back to inline URI parameters.

The factory is the whole connection, as in Apache Camel: host, port, credentials, virtual host, TLS, timeouts, recovery and client name all come from it. A URI that names a factory and also gives one of those parameters is refused when the endpoint is created, naming the parameters — it would otherwise go to another broker than the one written. Endpoint parameters (exchange, routing key, queue arguments, prefetch and the like) belong on the URI as usual.

Endpoints on the same factory share one connection; two factories are two connections, even with the same settings. Endpoints without a factory share a connection when all their connection parameters are the same, and get a connection of their own when any differs.

Publishing and consuming connections

By default producers and consumers with the same settings share one connection, as in Spring AMQP. The broker's flow control and memory or disk alarms block a publishing connection as a whole, and a consumer on it can then no longer acknowledge — RabbitMQ recommends separate connections. Two ways to get them:

  • two named factories, one for the producers and one for the consumers;
  • publisherConnection=true on an endpoint: its producer's sends, and its consumer's RPC replies, go over a second connection with the same settings, shown as "<clientName> (publisher)" in the management UI. A consumer's replies can be moved off its connection only this way.

At most two connections per factory (or per set of URI settings) either way, never one per endpoint.

When the broker blocks its publishers

Under a memory or disk alarm the broker stops reading from publishing connections and sends no publisher confirms until the alarm clears. A consumer that stopped reading and a queue without a length limit filling the disk is the usual way there. A send therefore waits at most confirmTimeout milliseconds (5000 by default, as Apache Camel's) for the broker to take it, then fails with RabbitMQPublishTimeoutException, a TimeoutException:

  • an ordinary send: the wait for the channel, the publish and the confirm;
  • a send in a transacted block: the block's publishes and the tx.commit;
  • a request-reply call: the request's publish; timeout bounds the wait for the reply.
.OnException<RabbitMQPublishTimeoutException>().Handled().To("seda://retry-later").End()
.To(Rabbit.Exchange("positions").ConfirmTimeout(2000))

A timed-out message may still reach the queue when the broker resumes, so a route that sends it again can deliver it twice. A queue whose messages may be lost under load (positions, statuses) gets a limit on the broker side: maxLength or maxLengthBytes with overflow=drop-head, or a messageTtl, or the same as a broker policy.

When the broker closes a channel

A channel-level error — a publish to an exchange that does not exist (404), a failed precondition — closes the channel and keeps the connection, so connection recovery does not reopen it.

  • Producer: the next send opens a new channel (and a new reply queue for replyTo=true); only the send that hit the error fails.
  • Consumer: it logs an Error saying it stopped receiving; unacknowledged deliveries go back to the queue. Restart the route. The same Error is logged when the broker cancels the subscription because the queue was deleted.
  • A lost connection is restored with its channels and subscriptions by automatic recovery (on by default). With automaticRecovery=false nothing restores it: restart the route.
context.AddToRegistry("prod", new RabbitMQConnectionFactory
{
    Host = "rabbit.internal",
    Username = "svc",
    Password = secrets.RabbitPassword,
});
// rabbitmq://orders?connectionFactory=prod

Unroutable messages

A publish with mandatory set that no queue takes comes back from the broker, and the send fails with RabbitMQUnroutableException (exchange, routing key, reply code) instead of the message vanishing. mandatory is on by default for direct and headers exchanges and for the default exchange, off for topic and fanout, where a message nobody subscribed to is normal; set it with mandatory=true|false. The same exception comes from every path:

  • an immediate send, when the broker returns it;
  • a request-reply call (replyTo=true), at once instead of after the timeout;
  • the sends of a .Transacted() block, when the block commits. The channel transaction has then committed the messages that did route, so a retry of the block sends those again.

For production queues consider an alternate exchange on the target exchange as well: the broker then keeps what does not route instead of returning it.

OnException<RabbitMQUnroutableException>()
    .Handled()
    .Log("No queue for ${header.region}: ${exception.message}")
    .To("rabbitmq://parking-lot")
.EndOnException();

TLS and login

ssl=true (or Ssl = true on a factory) encrypts the connection; the broker's TLS listener is usually port 5671, so set the port too — the default stays 5672. Every TLS setting below needs ssl=true: given without it, it would be ignored, so the endpoint is refused instead.

Setting (URI / factory) What it does
sslServerName The name the broker certificate must carry. Unset, each host of a cluster list is checked against its own name; set it when the certificate names a load balancer or an alias. The name is always checked.
sslCaCertPath / SslCaCertPath, SslCaCertificates Trust these roots (PEM file, or the certificates themselves on a factory) for the broker certificate instead of the system store — a private or corporate CA without installing it in the OS.
sslCertPath + sslCertPassword / ClientCertificate Client certificate for mutual TLS: a PFX file, or on a factory the X509Certificate2 itself (from the Windows store, a key vault). It must have its private key and be inside its validity period; both are checked before the handshake, naming the certificate.
sslProtocols Tls12, Tls13 or Tls12,Tls13. Unset, the OS chooses. SSL 3.0, TLS 1.0 and 1.1 are refused.
revocationMode + revocationSoftFail Revocation check of the broker certificate: NoCheck (default), Online (CRL/OCSP), Offline (OS cache). An undeterminable status is refused unless revocationSoftFail=true; a certificate that names no CRL or OCSP source passes, as in the AS4 connector.
authMechanism=External Log in with the client certificate (SASL EXTERNAL) — no password is sent; the broker takes the user from the certificate. Needs the broker's rabbitmq_auth_mechanism_ssl plugin.
context.AddToRegistry("prod", new RabbitMQConnectionFactory
{
    Host = "rmq1.internal, rmq2.internal",
    Port = 5671,
    Ssl = true,
    SslCaCertPath = "/etc/pki/corp-root.pem",
    ClientCertificate = certificateFromStore,        // mutual TLS
    AuthMechanism = RabbitMQAuthMechanism.External,  // the certificate is the login
    SslProtocols = SslProtocols.Tls13,
});

OAuth 2.0. A factory with OAuth2TokenEndpoint, OAuth2ClientId and OAuth2ClientSecret (and optionally OAuth2Scope) logs in with an access token from the client credentials grant instead of a password, and renews the token on the open connection before it expires, so the broker never closes the connection for an expired token. The token endpoint must be https (plain http only on the loopback address): the client secret is sent to it. Needs the broker's rabbitmq_auth_backend_oauth2 plugin. Any other source of credentials plugs in as CredentialsProvider (an ICredentialsProvider). OAuth2, CredentialsProvider and AuthMechanism=External are three ways to log in; a factory that sets two of them is refused.

context.AddToRegistry("prod", new RabbitMQConnectionFactory
{
    Host = "rmq.internal", Port = 5671, Ssl = true,
    OAuth2TokenEndpoint = "https://login.example.com/oauth2/token",
    OAuth2ClientId = "billing-service",
    OAuth2ClientSecret = secrets.BillingClientSecret,
    OAuth2Scope = "rabbitmq.read:*/* rabbitmq.write:*/*",
});

Endpoints that share a pooled connection share its TLS identity and login, so the inline pool key includes every TLS and login setting.

The integration tests run against a stand with a private CA, mutual TLS, EXTERNAL and OAuth 2.0 (profile rabbitmq-tls of the test stand docker-compose.tests.yml, see RabbitMQTlsBrokerTests).

Concurrency

The default is 1 concurrent consumer — the industry norm (Camel, Spring, the Azure SDK all ship 1): a single consumer preserves ordering and your handlers need no thread safety. Parallelism is an explicit opt-in:

concurrentConsumers=4       # a fixed worker count
concurrentConsumers=auto    # max(CPU count, 2) — the NServiceBus formula

Anything else — 0, a negative, a typo — fails at endpoint creation naming the option (the old int-typed option silently fell back to 1). Raising the value trades ordering for throughput: messages from the same queue are processed out of order, and your processors must be safe to run in parallel.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.8.0 45 12/1/2026
4.7.8 96 11/30/2026
4.7.7 99 11/28/2026
4.7.6 101 11/26/2026
4.7.5 108 11/24/2026
4.7.2 120 11/13/2026
4.7.1 117 11/11/2026
4.7.0 117 11/7/2026
4.6.2 111 11/5/2026
4.6.1 101 11/4/2026
4.6.0 111 11/3/2026
4.5.1 117 10/30/2026
4.5.0 121 10/29/2026
4.4.2 122 10/23/2026
4.4.1 128 10/21/2026
4.3.0 124 10/14/2026
4.2.3 120 10/8/2026
4.2.2 130 10/5/2026
4.2.0 135 9/30/2026
Loading failed