Class DelegatingTransportSubscriber
Base class for ITransportSubscriber decorators.
All virtual methods forward to the inner subscriber. Subclasses override to add behavior.
Follows the DelegatingChatClient pattern from Microsoft.Extensions.AI.
public abstract class DelegatingTransportSubscriber : ITransportSubscriber, IAsyncDisposable
- Inheritance
-
DelegatingTransportSubscriber
- Implements
- Inherited Members
- Extension Methods
Constructors
DelegatingTransportSubscriber(ITransportSubscriber)
Initializes a new instance of the DelegatingTransportSubscriber class.
protected DelegatingTransportSubscriber(ITransportSubscriber innerSubscriber)
Parameters
innerSubscriberITransportSubscriberThe inner subscriber to delegate to.
Properties
InnerSubscriber
Gets the inner subscriber that this decorator wraps.
protected ITransportSubscriber InnerSubscriber { get; }
Property Value
Source
Gets the source (topic, queue, subscription) this subscriber reads from.
public virtual string Source { get; }
Property Value
Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public virtual ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
GetService(Type)
Gets the underlying transport service (e.g., IConsumer, IChannel, SubscriberClient). Follows the IChatClient.GetService() pattern from Microsoft.Extensions.AI.
public virtual 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.
public virtual 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.