Path: redb-route/redb.Route.As4/As4Endpoint.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/As4Endpoint.cs
----
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.As4;
///
/// AS4 endpoint. Extends , which gives it statistics, health and Tsak
/// visibility. Produces an (send) or an (receive).
///
public sealed class As4Endpoint : EndpointBase
{
/// Logger of the owning component.
internal ILogger? Logger { get; }
/// Typed options, for the consumer and producer.
internal As4EndpointOptions EndpointOptions => Options;
/// The owning route context (registry lookups), via the component.
internal IRouteContext? Context => (Component as ComponentBase)?.Context;
///
/// Partner URL a producer posts to, rebuilt from a host-style URI (as4s://ap.partner/as4 has the
/// path ap.partner/as4), with as its query. Null for a
/// receive URI (as4:/as4/in).
///
internal string? PartnerUrl { get; }
/// Creates an AS4 endpoint.
public As4Endpoint(EndpointUri uri, As4Component component, As4EndpointOptions options)
: base(uri, component, options)
{
ArgumentNullException.ThrowIfNull(component);
Logger = component.Logger;
if (uri.Path.Length > 0 && !uri.Path.StartsWith('/'))
PartnerUrl = (options.UseTls ? "https://" : "http://") + uri.Path
+ (options.AddressQuery is null ? "" : "?" + options.AddressQuery);
}
///
public override IProducer CreateProducer()
{
RefuseOtherSidesOptions(EndpointRole.Producer);
if (PartnerUrl is null)
{
// as4:?partner=...: the address is the partner's, scheme and query included.
if (Uri.Path.Length > 0)
throw new InvalidOperationException(
$"AS4 send endpoint '{EndpointUri.Sanitize(Uri.NormalizedKey)}' has a receive path; a send endpoint is " +
"as4s://host[:port]/path, or as4:?partner=... to use the partner's Address.");
if (Options.UseTls || Options.AddressQuery is not null)
throw new InvalidOperationException(
$"AS4 send endpoint '{EndpointUri.Sanitize(Uri.NormalizedKey)}' has no address, so as4s and addressQuery say nothing: " +
"the partner's Address gives scheme and query. Write as4:?partner=....");
}
return new As4Producer(this, Options);
}
///
public override IConsumer CreateConsumer(IProcessor processor)
{
RefuseOtherSidesOptions(EndpointRole.Consumer);
return new As4Consumer(this, processor, Options);
}
///
/// An option only the other side reads (, as the http: connector declares it)
/// would bind and do nothing — idempotentRepository on a send looks like duplicate detection, timeout
/// on a receive like a limit. Refused, naming the parameters and never their values.
///
private void RefuseOtherSidesOptions(EndpointRole creating)
{
var written = redb.Route.Core.EndpointOptions.WrittenForOtherRole(Options.GetType(), Uri, creating);
if (written.Count == 0)
return;
var side = creating == EndpointRole.Producer ? "send" : "receive";
var other = creating == EndpointRole.Producer ? "receive" : "send";
throw new InvalidOperationException(
$"AS4 {side} endpoint '{EndpointUri.Sanitize(Uri.NormalizedKey)}' sets {string.Join(", ", written)}: " +
$"only a {other} endpoint reads {(written.Count == 1 ? "it" : "them")}.");
}
}