Table of Contents

Class PubsubSubscriptionManager

Namespace
Virtufin.Api.Services
Assembly
Virtufin.Api.dll

Manages pub/sub subscriptions and broadcasts messages to subscribers.

public class PubsubSubscriptionManager : SubscriptionManagerBase<PubsubSubscribeResponse, PubsubSubscription>
Inheritance
PubsubSubscriptionManager
Inherited Members

Constructors

PubsubSubscriptionManager(ILogger<PubsubSubscriptionManager>)

public PubsubSubscriptionManager(ILogger<PubsubSubscriptionManager> logger)

Parameters

logger ILogger<PubsubSubscriptionManager>

Methods

BroadcastToTopicAsync(string, byte[], string?, Dictionary<string, string>?)

Broadcasts a pub/sub event directly to all gRPC subscribers on the given topic. Packages the raw data and metadata into a PubsubSubscribeResponse and delivers through the in-process subscription channel.

public Task BroadcastToTopicAsync(string topic, byte[] data, string? messageId = null, Dictionary<string, string>? metadata = null)

Parameters

topic string

The topic to broadcast to.

data byte[]

The raw event data bytes.

messageId string

Optional message ID.

metadata Dictionary<string, string>

Optional metadata key-value pairs.

Returns

Task

GetAllSubscriptions()

public ConcurrentDictionary<string, ConcurrentDictionary<string, PubsubSubscription>> GetAllSubscriptions()

Returns

ConcurrentDictionary<string, ConcurrentDictionary<string, PubsubSubscription>>

GetIdleTimeout(PubsubSubscription)

Gets the idle timeout for a subscription.

protected override TimeSpan GetIdleTimeout(PubsubSubscription subscription)

Parameters

subscription PubsubSubscription

The subscription to get the timeout for.

Returns

TimeSpan

The idle timeout duration.

GetSubscriptionKey(PubsubSubscription)

Gets the subscription key for a subscription.

protected override string GetSubscriptionKey(PubsubSubscription subscription)

Parameters

subscription PubsubSubscription

The subscription to get the key for.

Returns

string

The subscription key string.

SendEventAsync(PubsubSubscription, PubsubSubscribeResponse, CancellationToken)

Sends an event to a subscription.

protected override Task SendEventAsync(PubsubSubscription subscription, PubsubSubscribeResponse evt, CancellationToken cancellationToken)

Parameters

subscription PubsubSubscription

The subscription to send to.

evt PubsubSubscribeResponse

The event to send.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

Subscribe(string, ChannelWriter<PubsubSubscribeResponse>)

Subscribes to a topic and returns a subscription ID.

public string Subscribe(string topic, ChannelWriter<PubsubSubscribeResponse> writer)

Parameters

topic string
writer ChannelWriter<PubsubSubscribeResponse>

Returns

string

UnsubscribeById(string)

Removes a subscription by its ID. Iterates all topics to find and remove the subscription.

public void UnsubscribeById(string subscriptionId)

Parameters

subscriptionId string

The subscription ID to remove.