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