Path: redb-route/redb.Route/Abstractions/IConsumerTemplate.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/Abstractions/IConsumerTemplate.cs ---- namespace redb.Route.Abstractions; /// /// Template for polling messages from endpoints programmatically, /// without creating a full route. Mirrors Apache Camel's ConsumerTemplate. /// /// Use for blocking poll, /// for timed poll, /// and for non-blocking poll. /// /// public interface IConsumerTemplate { /// Gets the route context associated with this template. IRouteContext Context { get; } /// Gets whether this template has been started and is ready for use. bool IsStarted { get; } // ── Receive (blocking) ── /// /// Receives an exchange from the specified endpoint URI, blocking until one is available. /// /// Source endpoint URI (e.g., "seda:queue"). /// Cancellation token. /// The received exchange. Task Receive(string endpointUri, CancellationToken ct = default); /// /// Receives an exchange from the specified endpoint, blocking until one is available. /// /// Source endpoint instance. /// Cancellation token. /// The received exchange. Task Receive(IEndpoint endpoint, CancellationToken ct = default); // ── Receive with timeout ── /// /// Receives an exchange from the specified endpoint URI, waiting up to the given timeout. /// Returns null if no exchange is available within the timeout. /// /// Source endpoint URI. /// Maximum time to wait. /// Cancellation token. /// The received exchange, or null if timed out. Task Receive(string endpointUri, TimeSpan timeout, CancellationToken ct = default); /// /// Receives an exchange from the specified endpoint, waiting up to the given timeout. /// Returns null if no exchange is available within the timeout. /// /// Source endpoint instance. /// Maximum time to wait. /// Cancellation token. /// The received exchange, or null if timed out. Task Receive(IEndpoint endpoint, TimeSpan timeout, CancellationToken ct = default); // ── ReceiveNoWait (non-blocking) ── /// /// Attempts to receive an exchange without waiting. /// Returns null immediately if no exchange is available. /// /// Source endpoint URI. /// Cancellation token. /// The received exchange, or null if none available. Task ReceiveNoWait(string endpointUri, CancellationToken ct = default); /// /// Attempts to receive an exchange without waiting. /// Returns null immediately if no exchange is available. /// /// Source endpoint instance. /// Cancellation token. /// The received exchange, or null if none available. Task ReceiveNoWait(IEndpoint endpoint, CancellationToken ct = default); // ── Typed body convenience ── /// /// Receives the message body from the specified endpoint URI, blocking until available. /// /// Source endpoint URI. /// Cancellation token. /// The body of the incoming message. Task ReceiveBody(string endpointUri, CancellationToken ct = default); /// /// Receives the message body from the specified endpoint URI, blocking until available, /// and converts it to . /// /// Expected body type. /// Source endpoint URI. /// Cancellation token. /// The typed body, or default. Task ReceiveBody(string endpointUri, CancellationToken ct = default); /// /// Receives the message body with a timeout. Returns default if timed out. /// /// Expected body type. /// Source endpoint URI. /// Maximum time to wait. /// Cancellation token. /// The typed body, or default if timed out or conversion failed. Task ReceiveBody(string endpointUri, TimeSpan timeout, CancellationToken ct = default); // ── Unit of work ── /// /// Completes the unit of work of an exchange handed out by a Receive call, Camel's /// doneUoW: only now does the source commit it — a polled file is deleted or moved, a /// broker message acknowledged. An exchange whose is set is /// rolled back instead (the file stays, the message is redelivered). Read the body before this /// call: the source releases the exchange's resources afterwards. ReceiveBody calls it /// itself. Until it is called the source keeps the exchange uncommitted; a stopped template rolls /// back every exchange still open. /// /// An exchange this template handed out and has not completed yet. /// The exchange was not handed out by this template, /// was already completed, or was rolled back when the template stopped. Task DoneUoW(IExchange exchange); // ── Lifecycle ── /// Starts the consumer template. Must be called before any receive methods. void Start(); /// /// Stops the consumer template and its cached consumers. Exchanges received but not completed /// with , and those the sources offered but no Receive took, are /// rolled back. /// void Stop(); }