Class TopicDaprSubscriptionRegistry
The gateway's in-process fan-out broker: one Dapr subscription per topic per API
process, shared by every Pubsub.Subscribe call on that topic, each message
written to every subscriber's channel.
public sealed class TopicDaprSubscriptionRegistry : IAsyncDisposable
- Inheritance
-
TopicDaprSubscriptionRegistry
- Implements
- Inherited Members
Remarks
Dapr pub/sub is competing-consumer: per-call Dapr subscriptions would load-balance
a topic's messages across callers instead of delivering each to all of them
(common/AGENTS.md lesson 6). The Dapr subscription opens with the first subscriber
and closes Linger after the last one left,
unless a subscriber joins meanwhile; it lives on its own token, so the subscriber
that opened it may leave first. The linger makes a quick resubscribe (a view
reopened, a reconnect, a client switching subscriptions) join the open
subscription: closing and reopening one would leave daprd's reader of the closed
one behind to take the topic's next message (common#28). If it ends on its own (the sidecar stream faulted), every
subscriber's channel completes with Unavailable and the next Subscribe opens
a fresh one.
Constructors
TopicDaprSubscriptionRegistry(IServiceProvider, DaprComponentOptions, ILogger<TopicDaprSubscriptionRegistry>, IConsumerGroupPositioner?, SidecarReaderSweeper?, PubsubSubscriptionOptions?)
public TopicDaprSubscriptionRegistry(IServiceProvider serviceProvider, DaprComponentOptions components, ILogger<TopicDaprSubscriptionRegistry> logger, IConsumerGroupPositioner? positioner = null, SidecarReaderSweeper? sweeper = null, PubsubSubscriptionOptions? subscriptions = null)
Parameters
serviceProviderIServiceProvidercomponentsDaprComponentOptionsloggerILogger<TopicDaprSubscriptionRegistry>positionerIConsumerGroupPositionersweeperSidecarReaderSweepersubscriptionsPubsubSubscriptionOptions
Properties
SubscriberCount
The subscribers across all topics.
public int SubscriberCount { get; }
Property Value
Methods
AcquireAsync(string, ChannelWriter<SubscribeResponse>, Action, CancellationToken)
Adds writer as a subscriber of topic, joining
the topic's Dapr subscription or opening it, and calls onActive
once the Dapr subscription is open. Disposing the handle removes the subscriber;
the last one leaving closes the Dapr subscription.
public Task<TopicDaprSubscriptionRegistry.SubscriptionHandle> AcquireAsync(string topic, ChannelWriter<SubscribeResponse> writer, Action onActive, CancellationToken ct)
Parameters
topicstringwriterChannelWriter<SubscribeResponse>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.