Path: redb-route/redb.Route.Amqp/AmqpEndpointOptions.cs
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/AmqpEndpointOptions.cs
----
using redb.Route.Abstractions;
using redb.Route.Batching;
using redb.Route.Core;
using AmqpSymbol = global::Amqp.Types.Symbol;
namespace redb.Route.Amqp;
///
/// Endpoint options for AMQP 1.0 transport. All properties are auto-bound from URI query parameters.
///
/// URI format: amqp://address?host=broker&port=5672&user=admin&password=admin&...
///
///
/// Supports: ActiveMQ Artemis, ActiveMQ Classic, Azure Service Bus, Amazon MQ, Qpid, any AMQP 1.0 broker.
///
///
public sealed class AmqpEndpointOptions : EndpointOptions
{
// ── Connection (override per-endpoint, fallback to component-level factory) ──
/// Named connection factory from registry. Takes priority over inline params.
[RegistryReference(typeof(AmqpConnectionFactory))]
public string? ConnectionFactory { get; set; }
///
/// Broker host (default: localhost). In a comma-separated list the connection opens to the first host; the others
/// are not tried.
///
public string Host { get; set; } = "localhost";
///
/// A registry reference (#name) to an that
/// decides which headers this endpoint carries between the exchange and AMQP application-properties (a request,
/// a consumed message, a reply both ways), in place of .
///
[RegistryReference(typeof(IHeaderFilterStrategy))]
public string? HeaderFilterStrategy { get; set; }
/// Broker port. (default: 5672)
public int Port { get; set; } = 5672;
/// SASL username.
public string? User { get; set; }
/// SASL password.
[Sensitive]
public string? Password { get; set; }
/// Container ID for this connection.
public string? ContainerId { get; set; }
/// Virtual host / AMQP hostname.
public string? VirtualHost { get; set; }
/// Enable SSL/TLS.
public bool Ssl { get; set; }
// ── AMQP terminus (Source/Target) ──
///
/// Terminus durability: 0 = none, 1 = configuration, 2 = unsettled-state.
/// Maps to Source.Durable / Target.Durable. (default: 0)
///
public uint Durable { get; set; }
///
/// Expiry policy for the terminus: link-detach, session-end, connection-close, never. (default: session-end)
///
public string ExpiryPolicy { get; set; } = "session-end";
/// Terminus timeout in seconds. (default: 0)
public uint TerminusTimeout { get; set; }
/// Distribution mode for the source: move or copy. (default: move)
public string? DistributionMode { get; set; }
/// Create dynamic terminus (broker assigns name). (default: false)
public bool Dynamic { get; set; }
///
/// JMS/AMQP selector filter expression. Applied as a Source filter.
/// Example: color='red' AND weight > 10
///
public string? FilterSelector { get; set; }
///
/// Terminus capabilities. Comma-separated AMQP symbols.
/// Examples: topic, queue, shared, global.
/// Artemis uses these to distinguish address types.
///
public string? Capabilities { get; set; }
// ── Link settlement ──
///
/// Sender settle mode: Unsettled (0), Settled (1), Mixed (2). (default: Mixed)
/// Controls at-most-once vs at-least-once delivery for producers.
///
public int SenderSettleMode { get; set; } = 2;
///
/// Receiver settle mode: First (0 = auto-ack), Second (1 = explicit ack). (default: First)
///
public int ReceiverSettleMode { get; set; }
// ── Consumer ──
/// Link credit (prefetch). How many messages the broker can send before ack. (default: 100)
public int Credit { get; set; } = 100;
///
/// When a delivery is settled (). Manual (default): accepted after a turn that ended
/// well, released for redelivery on failure (at-least-once). Auto: accepted on receipt, before the route runs
/// (at-most-once).
///
public AckMode AckMode { get; set; } = AckMode.Manual;
///
protected override string? UnknownParameterHint(string name)
=> name.Equals("autoAccept", StringComparison.OrdinalIgnoreCase)
? "'autoAccept' is replaced by 'ackMode': ackMode=manual (the default) accepts after the route, as autoAccept=true did; " +
"ackMode=auto accepts on receipt. autoAccept=false left every delivery unsettled, with nothing to settle it."
: null;
/// Concurrent consumer workers: a number or "auto" (= max(CPU, 2)). Default 1 (serial, ordering preserved).
// A string so "auto" binds verbatim instead of silently degrading to the int default.
public string? ConcurrentConsumers { get; set; }
/// Resolved consumer parallelism (see ).
public int ResolvedConcurrentConsumers => ConcurrencyOption.Resolve(ConcurrentConsumers, "concurrentConsumers");
/// Consumer receive timeout in seconds. 0 = infinite wait. (default: 60)
public int ReceiveTimeout { get; set; } = 60;
///
/// The consumer ignores a delivery's reply-to (Apache Camel disableReplyTo): the exchange is InOnly and no reply
/// is sent. In batch mode such a delivery then goes into the batch instead of being rejected.
///
public bool DisableReplyTo { get; set; }
// ── Batch mode ──
///
/// Batch mode (Apache Camel batching): the route gets one InOnly exchange whose body is a
/// List<IMessage> of up to deliveries of one receiver link, settled once
/// after the route: accepted on success, released for redelivery on failure, as a single delivery is.
///
public bool Batching { get; set; }
/// Largest number of deliveries in a batch (default ). At most .
public int? MaxBatchMessages { get; set; }
///
/// Batch mode: a batch with deliveries is sent on once no delivery came for this many milliseconds, restarted by
/// every delivery (default 1000).
///
public int PollTimeoutMs { get; set; } = 1000;
/// Batch mode: a batch is sent on once this many milliseconds have passed since its first delivery.
public int? BatchingIntervalMs { get; set; }
/// The batch options, or null outside batch mode. Set by .
internal BatchOptions? Batch { get; private set; }
///
/// Resolves the batch options. Fails, naming the endpoint, where batch mode cannot work: a batch option without
/// batching=true, a value out of range, a batch larger than (the broker sends no more
/// unsettled deliveries than the link's credit), and an endpoint configured for request-reply (a batch is InOnly).
///
internal void ResolveBatch(string endpoint)
{
Batch = BatchOptions.Resolve(endpoint, Batching, MaxBatchMessages, PollTimeoutMs, BatchingIntervalMs, Credit);
if (Batch is null)
return;
if (Batch.MaxMessages > Credit)
throw new InvalidOperationException(
$"Endpoint '{endpoint}': maxBatchMessages={Batch.MaxMessages} is larger than credit={Credit}; the broker " +
"never sends more unsettled deliveries than the link's credit, so such a batch would only ever close by its " +
"timeout. Raise credit, or lower maxBatchMessages.");
if (ReplyTo)
throw new InvalidOperationException(
$"Endpoint '{endpoint}': batching=true cannot be combined with replyTo=true: a batch is one-way (InOnly) " +
"and nobody would answer a request in it.");
}
// ── Producer: message defaults ──
/// Set AMQP header.durable on outgoing messages. (default: true)
public bool MessageDurable { get; set; } = true;
/// Default message priority (0–9). (default: 4)
public byte MessagePriority { get; set; } = 4;
/// Message priority as expression (e.g. ${body['priority']}). Resolved at runtime, overrides if set.
public string? MessagePriorityExpression { get; set; }
/// Default message TTL in milliseconds. 0 = no expiry.
public uint MessageTtl { get; set; }
/// Message TTL as expression (e.g. ${body['ttl']}). Resolved at runtime, overrides if set.
public string? MessageTtlExpression { get; set; }
/// Default content-type for outgoing messages. (default: text/plain)
public string ContentType { get; set; } = "text/plain";
/// AMQP subject/routing property on outgoing messages.
public string? Subject { get; set; }
/// AMQP group-id for message grouping.
public string? GroupId { get; set; }
/// Enable request/reply pattern (creates temp reply-to address). (default: false)
public bool ReplyTo { get; set; }
///
/// Apache Camel preserveMessageQos: an ordinary (not request-reply) send keeps the ReplyTo and
/// ReplyToGroupId headers as the message's reply-to. Off by default, as in Camel's JMS: a message consumed with a
/// sender's reply-to and forwarded to this endpoint does not carry that reply-to on, so no consumer answers into an
/// address of another system. The correlation id is always carried.
///
public bool PreserveMessageQos { get; set; }
///
/// Request/reply timeout in seconds; with it also bounds each step of a transaction
/// (declare, every send, discharge). (default: 30)
///
public int Timeout { get; set; } = 30;
///
/// Send-side timeout (seconds) for the consumer's RPC reply SenderLink.SendAsync.
/// Kept short on purpose: if the originating client has gone away its reply address is
/// dead, and a long send timeout would block the consumer slot. (default: 2)
///
public int ReplyTimeout { get; set; } = 2;
// ── Transacted ──
///
/// Producer: whether the send joins the enclosing .Transacted() block. Unset, it follows the block: deferred
/// until the database commits inside one, sent at once outside. true requires a block and fails outside one;
/// false sends at once even inside one, outside the block's transaction. A request-reply producer
/// () always sends at once and refuses true.
///
public bool? Transacted { get; set; }
///
/// Producer: the sends it defers in a .Transacted() block commit in one AMQP local transaction when the block
/// commits — a coordinator link declares it, the sends carry it, one discharge commits it — so they arrive together
/// or not at all; a rejected send, or any failure before the discharge, discharges it as failed. The broker must
/// support AMQP local transactions (ActiveMQ Artemis, Qpid, Azure Service Bus; not RabbitMQ's AMQP 1.0 plugin): one
/// that refuses the coordinator fails the commit. Unset, the deferred sends go out one after the other.
///
public bool LocalTransactions { get; set; }
// ── Topology ──
///
/// Declare the address on the broker if it doesn't exist. Requires broker support.
/// Artemis auto-creates by default. (default: false)
///
public bool Declare { get; set; }
///
/// Routing type for Artemis: ANYCAST (queue semantics) or MULTICAST (topic semantics).
/// Mapped to capabilities. (default: ANYCAST)
///
public string RoutingType { get; set; } = "ANYCAST";
///
public override void Validate()
{
if (Port is < 1 or > 65535)
throw new ArgumentException($"AMQP port must be 1–65535, got: {Port}");
if (Credit < 0)
throw new ArgumentException($"AMQP credit (prefetch) must be >= 0, got: {Credit}");
_ = ConcurrencyOption.Resolve(ConcurrentConsumers, "concurrentConsumers"); // loud on garbage
if (SenderSettleMode is < 0 or > 2)
throw new ArgumentException($"SenderSettleMode must be 0–2, got: {SenderSettleMode}");
if (ReceiverSettleMode is < 0 or > 1)
throw new ArgumentException($"ReceiverSettleMode must be 0–1, got: {ReceiverSettleMode}");
if (Durable > 2)
throw new ArgumentException($"Durable must be 0–2, got: {Durable}");
// A typo must fail at endpoint creation, not silently at terminus build time.
ResolveExpiryPolicy();
if (LocalTransactions && ReplyTo)
throw new ArgumentException(
"'localTransactions' commits deferred sends, and a request-reply producer (replyTo=true) never defers " +
"one: its request has to leave at once for the reply to come. Drop one of the two.");
if (LocalTransactions && Transacted == false)
throw new ArgumentException(
"'localTransactions' commits the sends deferred in a .Transacted() block, and 'transacted=false' sends at " +
"once, deferring none. Drop one of the two.");
}
///
/// Resolves the terminus capabilities as an array of AMQP symbols.
/// Combines explicit Capabilities with RoutingType for Artemis compatibility.
///
internal string[] ResolveCapabilities()
{
var caps = new List();
if (!string.IsNullOrEmpty(Capabilities))
{
caps.AddRange(Capabilities.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
}
// Artemis routing type as capability
if (!string.IsNullOrEmpty(RoutingType))
{
var rt = RoutingType.ToUpperInvariant() switch
{
"ANYCAST" => "queue",
"MULTICAST" => "topic",
_ => RoutingType.ToLowerInvariant()
};
if (!caps.Contains(rt, StringComparer.OrdinalIgnoreCase))
caps.Add(rt);
}
return caps.ToArray();
}
///
/// Maps the ExpiryPolicy string to the AMQP symbol value. A typo throws instead of silently
/// becoming session-end — on a durable subscription that silent fallback meant the broker
/// dropped the subscription between restarts.
///
internal AmqpSymbol ResolveExpiryPolicy()
{
return ExpiryPolicy.ToLowerInvariant() switch
{
"link-detach" => new AmqpSymbol("link-detach"),
"session-end" => new AmqpSymbol("session-end"),
"connection-close" => new AmqpSymbol("connection-close"),
"never" => new AmqpSymbol("never"),
_ => throw new ArgumentException(
$"Invalid value '{ExpiryPolicy}' for option 'expiryPolicy'. " +
"Valid values: link-detach, session-end, connection-close, never.")
};
}
}