Class TopicDaprSubscriptionRegistry
Manages one Dapr pubsub subscription per topic per API process, with a reference count of in-process gRPC callers sharing it.
Per the Pub/Sub Topics spec §Subscription Implementation Pattern: one Dapr subscription per topic per service process — NOT one per gRPC call. Per-call Dapr subscriptions would cause the same event to be load-balanced across callers instead of broadcast to each.
public sealed class TopicDaprSubscriptionRegistry : IAsyncDisposable
- Inheritance
-
TopicDaprSubscriptionRegistry
- Implements
- Inherited Members
Constructors
TopicDaprSubscriptionRegistry(IServiceProvider, ILogger<TopicDaprSubscriptionRegistry>)
public TopicDaprSubscriptionRegistry(IServiceProvider serviceProvider, ILogger<TopicDaprSubscriptionRegistry> logger)
Parameters
serviceProviderIServiceProviderloggerILogger<TopicDaprSubscriptionRegistry>
Methods
AcquireAsync(string, Func<TopicMessage, CancellationToken, Task<TopicResponseAction>>, Action, CancellationToken)
Returns a handle backed by either an existing Dapr subscription for the topic (refcount +1) or a freshly opened one. Disposing the handle releases the reference; when the last reference is released, the Dapr subscription is torn down.
public Task<TopicDaprSubscriptionRegistry.SubscriptionHandle> AcquireAsync(string topic, Func<TopicMessage, CancellationToken, Task<TopicResponseAction>> onMessage, Action onActive, CancellationToken ct)
Parameters
topicstringonMessageFunc<TopicMessage, CancellationToken, Task<TopicResponseAction>>onActiveActionctCancellationToken
Returns
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.