Interface ITransportSubscriber
Push-based transport subscription interface.
Unlike ITransportReceiver (pull-based, returns TransportReceivedMessage), this interface pushes messages to a callback handler. Transports with native push semantics (Kafka consumer groups, RabbitMQ BasicConsume, Azure Event Hubs, Google PubSub streaming pull) implement this interface directly.
Follows the same minimal-interface pattern as ITransportSender and ITransportReceiver.
public interface ITransportSubscriber : IAsyncDisposable
- Inherited Members
- Extension Methods
Properties
Source
Gets the source (topic, queue, subscription) this subscriber reads from.
string Source { get; }
Property Value
Methods
GetService(Type)
Gets the underlying transport service (e.g., IConsumer, IChannel, SubscriberClient). Follows the IChatClient.GetService() pattern from Microsoft.Extensions.AI.
object? GetService(Type serviceType)
Parameters
serviceTypeType
Returns
Remarks
The default implementation answers for any service this instance itself implements, so a transport that provides one directly need not override it. A transport overrides it to hand out its native SDK handle, and a decorator overrides it to answer for itself before deferring to the transport it wraps.
Exceptions
- ArgumentNullException
Thrown when
serviceTypeis null.
SubscribeAsync(Func<TransportReceivedMessage, CancellationToken, Task<MessageAction>>, CancellationToken)
Subscribes to receive messages via the provided handler callback.
The handler is invoked for each received message. The subscription runs until
the cancellationToken is cancelled or DisposeAsync() is called.
Task SubscribeAsync(Func<TransportReceivedMessage, CancellationToken, Task<MessageAction>> handler, CancellationToken cancellationToken)
Parameters
handlerFunc<TransportReceivedMessage, CancellationToken, Task<MessageAction>>Callback invoked for each received message. Return Acknowledge to acknowledge, Reject to reject, or Requeue to requeue the message.
cancellationTokenCancellationTokenCancellation token to stop the subscription.
Returns
- Task
A task that completes when the subscription ends.