Path: redb-route/redb.Route.As4/As4EndpointOptions.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.As4/As4EndpointOptions.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Http;
namespace redb.Route.As4;
///
/// Options of an AS4 endpoint, bound from URI query parameters. Only what may differ per endpoint or per
/// message lives here; the agreement (identities, certificates, algorithms) is the named
/// and its objects — there is no inline
/// alternative, so one partner has one source of truth.
///
/// checks what the URI alone decides. Everything that depends on the factory is
/// checked when the consumer or producer starts: the registry may be filled after the routes are defined.
///
///
public sealed class As4EndpointOptions : EndpointOptions
{
/// Default listen port of a receive endpoint.
public const int DefaultPort = 4090;
/// Default upper bound on a request body: 100 MB.
public const long DefaultMaxRequestBodySize = 100L * 1024 * 1024;
/// Default upper bound on the partner's response to a send: 4 MB (a receipt or an error is a few KB).
public const long DefaultMaxResponseBodySize = 4L * 1024 * 1024;
/// Default upper bound on the SOAP envelope (root MIME part), in characters: 1 M.
public const long DefaultMaxEnvelopeCharacters = 1024 * 1024;
// ── Node and partner ─────────────────────────────────────────────────────
/// Registry name of the (our node). Required.
[RegistryReference(typeof(As4ConnectionFactory))]
public string? ConnectionFactory { get; set; }
///
/// of the partner to send to (producer). May be an expression, e.g.
/// ${header.partner}. The name must be one of the node's .
///
[EndpointRole(EndpointRole.Producer)]
public DynamicValue? Partner { get; set; }
// ── Per-message business values (producer) ───────────────────────────────
/// Overrides the agreement's eb:Service; allowed only when the agreement permits it.
[EndpointRole(EndpointRole.Producer)]
public DynamicValue? Service { get; set; }
/// Overrides the agreement's eb:Action; allowed only when the agreement permits it.
[EndpointRole(EndpointRole.Producer)]
public DynamicValue? Action { get; set; }
/// eb:ConversationId. Default: a new id per message, or the redbAs4.conversationId header.
[EndpointRole(EndpointRole.Producer)]
public DynamicValue? ConversationId { get; set; }
///
/// eb:RefToMessageId — set on the reply of a Two-Way / Push-and-Push exchange. Default: the
/// redbAs4.refToMessageId header, else none.
///
[EndpointRole(EndpointRole.Producer)]
public DynamicValue? RefToMessageId { get; set; }
///
/// Query of the partner's address, without the ?: Domibus serves its domains as
/// /domibus?domain=name. The query of an as4 URI holds the endpoint's options, so the address
/// query travels in this option, encoded as one value; As4.Send(url) moves it here from the URL.
///
[EndpointRole(EndpointRole.Producer)]
public string? AddressQuery { get; set; }
/// Milliseconds to wait for the partner's HTTP response carrying the receipt. Default 60000.
[EndpointRole(EndpointRole.Producer)]
public int Timeout { get; set; } = 60000;
///
/// Upper bound in bytes on the partner's HTTP response to a send (producer), the counterpart of
/// on receipt. The response is read as a bounded stream: a larger one (a proxy's
/// error page, a broken partner) is refused as an invalid receipt without being read into memory.
/// Default .
///
[EndpointRole(EndpointRole.Producer)]
public long MaxResponseBodySize { get; set; } = DefaultMaxResponseBodySize;
///
/// Defer the send to the enclosing .Transacted() block. eDelivery requires a synchronous receipt,
/// so a sender always waits for the response and never defers: true fails when the URI is bound.
///
[EndpointRole(EndpointRole.Producer)]
public bool? Transacted { get; set; }
// ── Receive server (consumer) ────────────────────────────────────────────
///
/// Name of an IIdempotentRepository registered with context.AddIdempotentRepository(name, repo) —
/// the contract of the route-level IdempotentConsumer EIP and of the S3 consumer's option of the same name.
/// It remembers received message ids: a message received again is answered with a receipt and not delivered
/// twice (AS4 duplicate detection). Required on a receive endpoint — eDelivery AS4 1.16 mandates duplicate
/// detection, and which store holds the ids (memory, redb, SQL) decides whether it survives a restart and
/// works across cluster nodes, so it is named explicitly.
///
/// The keys are eb:MessageId as it is, the way Domibus and Holodeck keep them: a message id is globally
/// unique by the ebMS contract, whoever sends it. Give the endpoint a repository of its own — one shared with
/// another route's business keys, or reused by a partner's colliding id, would answer a new message with the
/// receipt of a duplicate and not deliver it.
///
///
[EndpointRole(EndpointRole.Consumer)]
[RegistryReference(typeof(IIdempotentRepository))]
public string? IdempotentRepository { get; set; }
///
/// Receive side: milliseconds after which a claim of a message id that was never confirmed is taken to be left by a
/// stopped node and taken over, so its message is processed. A younger one means the message is still in a route: a
/// copy that arrives meanwhile is refused with and and no
/// ebMS signal, not answered with a receipt, and the sender resends it. Takes effect with a repository that keeps the
/// confirmed state (the redb, SQL and in-memory ones do). Default 600000 (10 minutes).
///
[EndpointRole(EndpointRole.Consumer)]
public int InFlightClaimTimeout { get; set; } = 600_000;
///
/// If true, the consumer sets the exchange body of a single-payload message to a Stream instead of a byte
/// array, as streamBody does for the File, SFTP and S3 consumers. The stream is closed by
/// Exchange.DisposeAsync(). Either way the connector itself spools a large request and its payloads to a
/// temporary file (the core stream cache) instead of memory, and hands a payload to the route only after it is
/// decrypted, its signature verified and it is decompressed. (default: false)
///
[EndpointRole(EndpointRole.Consumer)]
public bool StreamBody { get; set; }
///
/// If true, the consumer always sets the exchange body to the list of , in the order of
/// eb:PartInfo: one entry for a single payload, none for a message without payloads. Each entry keeps the
/// Content-ID and the part properties, which a single payload handed as the body itself does not carry. The same
/// list is what a send endpoint takes, so a route can pass a received message on as it came. Takes precedence over
/// . (default: false)
///
[EndpointRole(EndpointRole.Consumer)]
public bool PayloadList { get; set; }
/// Bind address of the receive server. Default 0.0.0.0.
[EndpointRole(EndpointRole.Consumer)]
public string Host { get; set; } = "0.0.0.0";
/// Listen port of the receive server. Default .
[EndpointRole(EndpointRole.Consumer)]
public int Port { get; set; } = DefaultPort;
/// Serve over HTTPS. Set by the as4s scheme.
public bool UseTls { get; set; }
/// PFX the receive server presents over TLS; else the factory's. A TLS receiver with neither refuses to start.
[EndpointRole(EndpointRole.Consumer)]
public string? SslCertPath { get; set; }
/// Password for .
[EndpointRole(EndpointRole.Consumer)]
[Sensitive]
public string? SslCertPassword { get; set; }
/// Whether the receive server asks partners for a TLS client certificate.
[EndpointRole(EndpointRole.Consumer)]
public As4ClientCertificateMode ClientCertificateMode { get; set; } = As4ClientCertificateMode.NoCertificate;
/// Thumbprints (comma-separated) an accepted client certificate must match; null: any valid one.
[EndpointRole(EndpointRole.Consumer)]
public string? AllowedClientThumbprints { get; set; }
/// Upper bound on a request body in bytes. Default .
[EndpointRole(EndpointRole.Consumer)]
public long MaxRequestBodySize { get; set; } = DefaultMaxRequestBodySize;
///
/// Upper bound on the SOAP envelope in characters. Applies to the envelope only — payloads travel as
/// attachments and are bounded by . Default .
///
public long MaxEnvelopeCharacters { get; set; } = DefaultMaxEnvelopeCharacters;
/// Maximum concurrent executions of this receiver's pipeline; 0 (default) = unlimited.
[EndpointRole(EndpointRole.Consumer)]
public int MaxConcurrentRequests { get; set; }
/// Requests over the limit that wait for a permit (FIFO); 0 (default) = reject at once.
[EndpointRole(EndpointRole.Consumer)]
public int RequestQueueLimit { get; set; }
/// Status code of a shed request. Default 503: an AS4 sender retries on it.
[EndpointRole(EndpointRole.Consumer)]
public int RejectStatusCode { get; set; } = 503;
/// Retry-After of a shed request in seconds; 0 = not sent. Default 1.
[EndpointRole(EndpointRole.Consumer)]
public int RetryAfterSeconds { get; set; } = 1;
///
public override void Validate()
{
if (string.IsNullOrWhiteSpace(ConnectionFactory))
throw new ArgumentException("AS4 endpoint requires 'connectionFactory': the registry name of an As4ConnectionFactory.");
if (Port is < 1 or > 65535)
throw new ArgumentOutOfRangeException(nameof(Port), Port, "AS4 port must be between 1 and 65535.");
if (Timeout < 0)
throw new ArgumentOutOfRangeException(nameof(Timeout), Timeout, "AS4 timeout must not be negative.");
if (AddressQuery is not null && (AddressQuery.Length == 0 || AddressQuery.StartsWith('?') || AddressQuery.Contains('#')))
throw new ArgumentException("AS4 addressQuery is the query of the partner's address without '?' and without a fragment, " +
"such as 'domain=name'.");
if (MaxRequestBodySize <= 0)
throw new ArgumentOutOfRangeException(nameof(MaxRequestBodySize), MaxRequestBodySize, "AS4 maxRequestBodySize must be positive.");
if (MaxResponseBodySize <= 0)
throw new ArgumentOutOfRangeException(nameof(MaxResponseBodySize), MaxResponseBodySize, "AS4 maxResponseBodySize must be positive.");
if (MaxEnvelopeCharacters <= 0)
throw new ArgumentOutOfRangeException(nameof(MaxEnvelopeCharacters), MaxEnvelopeCharacters, "AS4 maxEnvelopeCharacters must be positive.");
// eDelivery AS4 1.16 fixes the receipt to the HTTP response of the same request, so a sender always waits for it:
// the URI alone decides this, so it fails in Validate as RabbitMQ refuses ackMode=auto with transacted.
if (Transacted == true)
throw new ArgumentException("AS4 transacted=true is not supported: an AS4 send waits for its receipt in the response " +
"and cannot be deferred to the end of a transaction.");
if (ClientCertificateMode != As4ClientCertificateMode.NoCertificate && !UseTls)
throw new ArgumentException("AS4 clientCertificateMode needs TLS: a client certificate is presented in the TLS handshake. Use the as4s scheme.");
if (InFlightClaimTimeout < 1)
throw new ArgumentOutOfRangeException(nameof(InFlightClaimTimeout), InFlightClaimTimeout, "AS4 inFlightClaimTimeout must be positive.");
ConcurrencyLimitOptions.ValidateShape(MaxConcurrentRequests, RequestQueueLimit, RejectStatusCode, RetryAfterSeconds);
}
}