Path: redb-route/redb.Route/Core/EndpointSides.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/Core/EndpointSides.cs ---- using System.Reflection; using redb.Route.Abstractions; namespace redb.Route.Core; /// /// The sides of a component: both, unless its class declares the only one it has with /// (Apache Camel's producerOnly / consumerOnly). The context, the /// Route-XML catalog, the editor schema and check all read this one declaration, and refuse the missing side /// in the one message builds. /// public static class EndpointSides { /// The declaration on ; null for both sides. public static EndpointRoleAttribute? Declaration(Type componentType) { ArgumentNullException.ThrowIfNull(componentType); return componentType.GetCustomAttribute(inherit: true); } /// The only side has; null for both. public static EndpointRole? Of(IComponent component) { ArgumentNullException.ThrowIfNull(component); return Declaration(component.GetType())?.Role; } /// /// The refusal of the side does not have, given the only one it has, with the /// component's hint when there is one. /// public static string MissingSide(string scheme, EndpointRole only, string? hint) { var text = only == EndpointRole.Producer ? $"{scheme} has no consumer side: a route cannot start from it ({scheme} is producer-only)." : $"{scheme} has no producer side: a route cannot send to it ({scheme} is consumer-only)."; return string.IsNullOrWhiteSpace(hint) ? text : text + " " + hint; } /// /// Throws , the exception the components throw themselves, when /// 's component has no side. /// public static void Refuse(IEndpoint endpoint, EndpointRole creating) { ArgumentNullException.ThrowIfNull(endpoint); if (Declaration(endpoint.Component.GetType()) is not { } declaration || declaration.Role == creating) return; throw new NotSupportedException(MissingSide(endpoint.Uri.Scheme, declaration.Role, declaration.Hint)); } /// The producer of , once found that it has one. public static IProducer CreateProducerOnItsSide(this IEndpoint endpoint) { Refuse(endpoint, EndpointRole.Producer); return endpoint.CreateProducer(); } /// The consumer of , once found that it has one. public static IConsumer CreateConsumerOnItsSide(this IEndpoint endpoint, IProcessor processor) { Refuse(endpoint, EndpointRole.Consumer); return endpoint.CreateConsumer(processor); } }