Path: redb-route/redb.Route.Amqp/README.md Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Amqp/README.md ---- # redb.Route.Amqp AMQP 1.0 transport for redb.Route via AMQPNetLite. Supports ActiveMQ Artemis, ActiveMQ Classic, Azure Service Bus, Amazon MQ, Qpid, and any AMQP 1.0 compliant broker. [![NuGet](https://img.shields.io/nuget/v/redb.Route.Amqp?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.Route.Amqp) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../../LICENSE) ## Installation ```bash dotnet add package redb.Route.Amqp ``` ## Usage ### Fluent DSL ```csharp using redb.Route.Amqp; // Consume from AMQP address From(AmqpDsl.Address("orders") .Host("artemis.local").Port(5672) .User("admin").Password("secret") .Credit(10) .Durable(2)) // terminus durability: 0 None, 1 Configuration, 2 UnsettledState .Log("Received order: ${body}") .To("direct://process"); // Produce to AMQP address From("direct://send") .To(AmqpDsl.Address("events") .Host("artemis.local") .User("admin").Password("secret") .MessageDurable() .ContentType("application/json")); // Azure Service Bus From(AmqpDsl.Address("orders") .Host("mybus.servicebus.windows.net").Port(5671) .User("policy-name").Password("shared-access-key") .Ssl() .ContainerId("route-consumer")) .To("direct://handle"); ``` ## Fluent Builder API | Category | Methods | |----------|---------| | **Connection** | `.Host()`, `.Port()`, `.User()`, `.Password()`, `.ContainerId()`, `.VirtualHost()`, `.Ssl()`, `.ConnectionFactory()` | | **Link** | `.Durable(mode)`, `.ExpiryPolicy()`, `.TerminusTimeout()`, `.DistributionMode()`, `.Dynamic()`, `.FilterSelector()`, `.Capabilities()`, `.SenderSettleMode()`, `.ReceiverSettleMode()` | | **Consumer** | `.Credit()`, `.AckMode()`, `.ConcurrentConsumers()`, `.ReceiveTimeout()`, `.DisableReplyTo()`, `.Batching()`, `.MaxBatchMessages()`, `.PollTimeoutMs()`, `.BatchingIntervalMs()` | | **Producer** | `.MessageDurable()`, `.MessagePriority()`, `.MessageTtl()`, `.ContentType()`, `.Subject()`, `.GroupId()`, `.ReplyTo()`, `.PreserveMessageQos()`, `.Timeout()`, `.Transacted()`, `.LocalTransactions()`, `.Declare()`, `.RoutingType()` | ## A failed delivery With `ackMode=manual` (the default) a delivery is accepted after the route ends well. When the route fails, the consumer gives the delivery back as a failed one: the AMQP `modified` outcome with `delivery-failed`. The broker counts the attempt and delivers the message again; a message that always fails stops at the broker's maximum delivery count (ActiveMQ Artemis: `max-delivery-attempts`, 10 by default, then the dead letter address). With `ackMode=auto` the delivery is accepted on receipt, before the route, and a failure does not bring it back. ## 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. Apache Camel has no batch consumer for AMQP; the contract is redb.Route's own, the same as for Kafka, RabbitMQ, IBM MQ and SQS. - `maxBatchMessages` caps the batch (default and maximum: `credit`, as the broker never sends a link more unsettled deliveries than its credit); `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 `credit` and `batching=true` with `replyTo=true` fail the start. - The body is a `List`, one message per delivery with its own body, application properties and AMQP properties as headers, even for a batch of one; the size is `body.Count`. `redbAmqp.Address` is set on the batch message. The exchange is InOnly. `Split` over the body gives each part its delivery. - `concurrentConsumers` workers each own a receiver link and collect and run one batch at a time. - Every delivery of the batch is accepted after the route. A failed batch follows the rule of a failed delivery for every delivery in it: each is given back as failed (see above), and the broker delivers it again up to its maximum delivery count. With `ackMode=auto` the deliveries are accepted on receipt, before the route, and a failure does not bring them back. - 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 (the AMQP `rejected` outcome; ActiveMQ Artemis moves it to the dead letter address), with an error in the log and the endpoint statistics. `disableReplyTo=true` (Apache Camel's name, single mode too: no reply, the exchange is InOnly) batches such deliveries and nobody replies. - A batch half collected when the consumer stops is not run: its deliveries are given back to the broker (released, or returned on detach). The stop lets the batches in flight settle, then closes the links. ## A list body This producer does not send a list: a list of `IMessage` is refused with the advice to `Split` it, and any other list whose text would be its type name is refused too. ## Transactions Inside a route's `.Transacted()` block a send **joins the transaction**: it goes out once the database has committed and is dropped if the block rolls back. `.Transacted(false)` sends at once, outside the transaction; `.Transacted()` requires an enclosing block and fails the step outside one. A request-reply producer (`.ReplyTo()`) always sends at once and refuses `.Transacted()`. The AMQP client would enlist a send in the ambient `System.Transactions` transaction by itself. The connector never lets it: a send that leaves at once runs with the ambient transaction suppressed and a deferred one after the transaction closed, so the broker never becomes a second resource next to the database. See the framework-wide **Transactions** guide (`TRANSACTIONS.md` in the [redb.Route repository](https://github.com/redbase-app/redb)). ### Several sends in one block: `localTransactions` By default the sends a producer deferred in a block go out one after the other: a failure part-way leaves the earlier ones sent. With `localTransactions=true` (`.LocalTransactions()`) they commit in one **AMQP local transaction**: the connector opens a link to the broker's transaction coordinator, declares a transaction, sends every message carrying it and discharges it once — all of them arrive, or none. A send that cannot complete (the broker refuses it, or does not settle it within `timeout` seconds — Artemis withholds credit on a full address) discharges the transaction as failed, and the block's commit fails. The producer's transactions take turns on its link. The broker must support AMQP local transactions: ActiveMQ Artemis, Apache Qpid, Azure Service Bus do; RabbitMQ's AMQP 1.0 plugin does not, and a broker that refuses the coordinator fails the commit with that said. The client's own `System.Transactions` support is not used: its discharge never got an answer from Artemis, while the same transaction driven through the protocol's own frames is answered at once. ## Headers Exchange headers become application-properties of a sent message and of a reply, and the application-properties of a delivery or a reply come back as exchange headers. The standard property names (`MessageId`, `CorrelationId`, `Subject`...) go into the message properties instead; `redbAmqp.*` 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` and `ReplyToGroupId` headers out, so a message consumed with a sender's reply-to and forwarded here does not make another consumer answer into an address of another system, as in Apache Camel's JMS. `preserveMessageQos=true` (`.PreserveMessageQos()`) keeps them, for a bridge that needs them 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, in both directions of a request and a reply. It replaces the default, `AmqpHeaderFilterStrategy`, entirely; derive from that class to add to it. The standard properties, the consumer's `redbAmqp.*` metadata and the trace context are set whatever the strategy says. ```csharp ctx.AddToRegistry("correlationOnly", new DefaultHeaderFilterStrategy { OutFilter = ["Correlation-ID"], FilterOnMatch = false, // a whitelist: only the listed headers go out }); // amqp://orders?host=localhost&headerFilterStrategy=#correlationOnly ``` ## Part of [redb.Route](../README.md) — 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. ```csharp context.AddToRegistry("prod", new AmqpConnectionFactory { Host = "broker.internal", User = "svc-orders", Password = secrets.AmqpPassword, }); // amqp://orders?connectionFactory=prod ``` ## 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. A MULTICAST address (`routingType=MULTICAST` or the `topic` capability) and a dynamic node (`dynamic=true`) run one receiver link whatever the value, with a warning: there every link is a subscription or a node of its own, so N links would process each message N times instead of sharing them, as IBM MQ topics do. ## Dynamic node `dynamic=true` with no address asks the broker to create a node and name it (AMQP 1.0, 3.5.3). The consumer reads that node, and `AmqpConsumer.Address` and the `redbAmqp.Address` header carry its name once the consumer has started, for senders to reach it. A producer with `dynamic=true` sends to a node the broker creates for it and logs its name. An endpoint with both an address and `dynamic=true` is refused. ## Start `Start()` returns once the broker has accepted every receiver link of the consumer, so a MULTICAST subscription is in place and a message sent right after the start is received. A link the broker refuses (an address it does not serve, a routing type the address lacks, no permission) fails the start with `AMQP consumer amqp:
cannot start: the broker refused the receiver link (: )`; no answer within `timeout` seconds fails it too. ## A lost link When the broker detaches a receiver link (a forced detach, a deleted address, a restart) or the connection under it drops, the worker attaches its link again on a new session, on a new connection when the old one is gone. The deliveries the old link held unsettled come back from the broker. While the link is away the endpoint's health is `Warning`, then `Critical` once an attempt to attach it failed; a Warning is logged when it is lost and an Information when it is back, and `Reconnects` counts each return. Attempts follow `RedbRoute:Reconnect` (delay, multiplier, cap, attempt timeout); a loss is not counted in `Errors`. With `dynamic=true` the new link gets a new node from the broker, and `AmqpConsumer.Address` names it. ## Tracing On the `redb.Route` activity source (`AddSource("redb.Route")`). The W3C context travels in the application properties: `traceparent`, `tracestate`, `baggage`. - **Consumer.** One `Consumer` span per message, `{address} receive`, over the whole unit of work, settlement included. Its parent is the sender's `traceparent`; without one it is a root, never a child of the activity the receive loop inherited from whoever started the routes. The sender's baggage is back on it, the route's spans are its children, it carries `redb.route.endpoint`, `messaging.message.id` and `messaging.amqp.subject`, and a failed route marks it an error. - **Producer.** One `Producer` span per send, `{address} publish`; an error when the send fails. The message carries the context of this span: a `traceparent` the header bridge copied from a received message is replaced. - `RouteEngineOptions.EnableTelemetry = false` opens neither span. A context that came in still goes out.