Class GatewaySubscriptionManager
In-process broadcast broker for the Gateway.Subscribe RPC.
One broker per topic; multiple gRPC callers on the same topic all
receive every message via BroadcastToTopicAsync(string, string, string, string, string, string, byte[], string, string, string).
public class GatewaySubscriptionManager : SubscriptionManagerBase<SubscribeResponse, GatewaySubscription>
- Inheritance
-
GatewaySubscriptionManager
- Inherited Members
Remarks
Per the Pub/Sub Topics spec §Subscription Implementation Pattern:
one Dapr subscription per topic per API process (managed by
TopicDaprSubscriptionRegistry); this class fans out
to multiple in-process gRPC callers. The caller-side envelope is
SubscribeResponse (CloudEvent proto envelope), in
contrast to PubsubSubscriptionManager which also uses the
SubscribeResponse envelope.
Constructors
GatewaySubscriptionManager(ILogger<GatewaySubscriptionManager>)
public GatewaySubscriptionManager(ILogger<GatewaySubscriptionManager> logger)
Parameters
loggerILogger<GatewaySubscriptionManager>
Methods
BroadcastToTopicAsync(string, string, string, string, string, string, byte[], string, string, string)
Broadcasts a parsed CloudEvent envelope to all in-process
gRPC subscribers on the topic. The Dapr message handler in
GatewayService.Subscribe calls this once per received
Dapr message.
public Task BroadcastToTopicAsync(string topic, string id, string source, string type, string specVersion, string dataContentType, byte[] data, string pubsubTopic, string pubsubName, string path)
Parameters
topicstringidstringsourcestringtypestringspecVersionstringdataContentTypestringdatabyte[]pubsubTopicstringpubsubNamestringpathstring
Returns
GetIdleTimeout(GatewaySubscription)
Gets the idle timeout for a subscription.
protected override TimeSpan GetIdleTimeout(GatewaySubscription subscription)
Parameters
subscriptionGatewaySubscriptionThe subscription to get the timeout for.
Returns
- TimeSpan
The idle timeout duration.
GetSubscriptionKey(GatewaySubscription)
Gets the subscription key for a subscription.
protected override string GetSubscriptionKey(GatewaySubscription subscription)
Parameters
subscriptionGatewaySubscriptionThe subscription to get the key for.
Returns
- string
The subscription key string.
SendEventAsync(GatewaySubscription, SubscribeResponse, CancellationToken)
Sends an event to a subscription.
protected override Task SendEventAsync(GatewaySubscription subscription, SubscribeResponse evt, CancellationToken cancellationToken)
Parameters
subscriptionGatewaySubscriptionThe subscription to send to.
evtSubscribeResponseThe event to send.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Subscribe(string, ChannelWriter<SubscribeResponse>)
Subscribes to a topic. Returns a unique subscription ID. Each ID is a fresh GUID; pass it back to UnsubscribeById(string) when the gRPC call ends.
public string Subscribe(string topic, ChannelWriter<SubscribeResponse> writer)
Parameters
topicstringwriterChannelWriter<SubscribeResponse>
Returns
UnsubscribeById(string)
Removes a subscription by its ID. Iterates all topics.
public void UnsubscribeById(string subscriptionId)
Parameters
subscriptionIdstring