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 buffer (Virtufin.Api.Services.SubscriberBuffer). A batch
entry (Virtufin.Api.Services.PubsubBatchEntry) is written as its single events, in order,
or, to a subscriber that asked for whole batches, as one response holding the
stored bytes (openspec protobuf-event-path).
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 buffer ends with Unavailable and the next Subscribe opens
a fresh one.
Delivery never waits for a subscriber (the sidecar serves all of a pod's topics
with one set of workers, so a waiting handler stalls every other topic), and
nothing is dropped for one that is behind: a subscriber whose buffer has no room
leaves live delivery and is served from the topic's stream at its own pace, from
where it stands, until it has caught up and joins live delivery again (the
CatchUp part of this class; openspec event-throughput). Its call ends
only when that cannot work: with DataLoss when the stream no longer
holds what it still needs, with ResourceExhausted when the backend has
no stream to read from or the subscriber takes nothing for
Stall.
Constructors
TopicDaprSubscriptionRegistry(IServiceProvider, DaprComponentOptions, ILogger<TopicDaprSubscriptionRegistry>, IConsumerGroupPositioner?, SidecarReaderSweeper?, PubsubSubscriptionOptions?, PubsubDeliveryOptions?)
public TopicDaprSubscriptionRegistry(IServiceProvider serviceProvider, DaprComponentOptions components, ILogger<TopicDaprSubscriptionRegistry> logger, IConsumerGroupPositioner? positioner = null, SidecarReaderSweeper? sweeper = null, PubsubSubscriptionOptions? subscriptions = null, PubsubDeliveryOptions? delivery = null)
Parameters
serviceProviderIServiceProvidercomponentsDaprComponentOptionsloggerILogger<TopicDaprSubscriptionRegistry>positionerIConsumerGroupPositionersweeperSidecarReaderSweepersubscriptionsPubsubSubscriptionOptionsdeliveryPubsubDeliveryOptions
Properties
SubscriberCount
The subscribers across all topics.
public int SubscriberCount { get; }
Property Value
Methods
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.