Class PubsubSubscriptionManager
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
loggerILogger<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
topicstringThe topic to broadcast to.
databyte[]The raw event data bytes.
messageIdstringOptional message ID.
metadataDictionary<string, string>Optional metadata key-value pairs.
Returns
GetAllSubscriptions()
public ConcurrentDictionary<string, ConcurrentDictionary<string, PubsubSubscription>> GetAllSubscriptions()
Returns
GetIdleTimeout(PubsubSubscription)
Gets the idle timeout for a subscription.
protected override TimeSpan GetIdleTimeout(PubsubSubscription subscription)
Parameters
subscriptionPubsubSubscriptionThe 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
subscriptionPubsubSubscriptionThe 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
subscriptionPubsubSubscriptionThe subscription to send to.
evtPubsubSubscribeResponseThe event to send.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Subscribe(string, ChannelWriter<PubsubSubscribeResponse>)
Subscribes to a topic and returns a subscription ID.
public string Subscribe(string topic, ChannelWriter<PubsubSubscribeResponse> writer)
Parameters
topicstringwriterChannelWriter<PubsubSubscribeResponse>
Returns
UnsubscribeById(string)
Removes a subscription by its ID. Iterates all topics to find and remove the subscription.
public void UnsubscribeById(string subscriptionId)
Parameters
subscriptionIdstringThe subscription ID to remove.