Class GatewayClient
Dynamic proxy for the API Gateway. Service names are accessed as properties, and backend RPC methods are called dynamically on the returned ServiceClient.
client.Gateway.workmanager triggers TryGetMember(GetMemberBinder, out object?),
which creates or returns a cached ServiceClient for "workmanager".
service.ListWorkers() triggers TryGetMember(GetMemberBinder, out object?),
which returns a callable that invokes via the Gateway's InvokeJson RPC.
Provides service discovery, method listing, invocation, publishing, and streaming capabilities.
public class GatewayClient : DynamicObject, IDynamicMetaObjectProvider
- Inheritance
-
GatewayClient
- Implements
- Inherited Members
Examples
using var client = new ApiClient();
var workers = await client.Gateway.workmanager.ListWorkers();
// Equivalent to:
var workers = await client.InvokeAsync("workmanager", "ListWorkers");
Constructors
GatewayClient(GrpcChannel)
Creates a new GatewayClient with the specified gRPC channel.
public GatewayClient(GrpcChannel channel)
Parameters
channelGrpcChannelThe gRPC channel to use for communication.
Methods
DeleteBulkStateAsync(string, IEnumerable<string>, bool, CancellationToken)
Deletes multiple state entries for a service.
public Task<DeleteBulkStateResponse> DeleteBulkStateAsync(string service, IEnumerable<string> keys, bool publishChange = false, CancellationToken cancellationToken = default)
Parameters
servicestringkeysIEnumerable<string>publishChangeboolIf true, a single state.change event is published for the whole bulk. Default false.
cancellationTokenCancellationToken
Returns
- Task<DeleteBulkStateResponse>
DeleteStateAsync(string, string, bool, bool, CancellationToken)
Deletes a state entry and broadcasts a delete event to subscribers asynchronously.
public Task<DeleteStateResponse> DeleteStateAsync(string service, string key, bool publishChange = false, bool includeValue = false, CancellationToken cancellationToken = default)
Parameters
servicestringThe service name.
keystringThe state key.
publishChangeboolIf true, a state.change event is published. Default false.
includeValueboolIf true, the last value is included in the state change event payload. Only relevant when publishChange=true.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DeleteStateResponse>
DeleteStateResponse with success status.
GetBulkStateAsync(string, IEnumerable<string>, CancellationToken)
Gets multiple state values for a service and list of keys.
public Task<List<StateItemDto>> GetBulkStateAsync(string service, IEnumerable<string> keys, CancellationToken cancellationToken = default)
Parameters
servicestringkeysIEnumerable<string>cancellationTokenCancellationToken
Returns
GetService(string)
Gets a client for a specific service.
public ServiceClient GetService(string name)
Parameters
namestringThe service name.
Returns
- ServiceClient
A ServiceClient for the service.
Remarks
ServiceClients are cached internally. Calling this method multiple times with the same service name returns the same cached instance.
GetStateAsync(string, string, CancellationToken)
Gets a single state value asynchronously by service and key.
public Task<(string Value, string Etag)> GetStateAsync(string service, string key, CancellationToken cancellationToken = default)
Parameters
servicestringThe service name.
keystringThe state key.
cancellationTokenCancellationTokenCancellation token.
Returns
InvokeAsync(string, string, Dictionary<string, object?>?)
Invokes a method on a service asynchronously.
public Task<Dictionary<string, object?>> InvokeAsync(string service, string method, Dictionary<string, object?>? requestData = null)
Parameters
servicestringThe service name.
methodstringThe method name.
requestDataDictionary<string, object>Optional request data as dictionary.
Returns
- Task<Dictionary<string, object>>
The response as a dictionary.
Remarks
The polymorphic Dictionary<string, object?>
payload is (de)serialized via Virtufin.Api.Client.GatewayClient.JsonOptions,
which sets an explicit DefaultJsonTypeInfoResolver
so reflection-based dispatch works regardless of the
process-wide IsReflectionEnabledByDefault flag.
See Virtufin.Api.Client.GatewayClient.JsonOptions for the AOT caveat.
Exceptions
- InvalidOperationException
Thrown when the invocation fails.
ListMethodsAsync(string)
Lists all methods for a given service asynchronously.
public Task<List<Dictionary<string, object?>>> ListMethodsAsync(string service)
Parameters
servicestringThe service name.
Returns
- Task<List<Dictionary<string, object>>>
List of method information dictionaries.
ListServicesAsync()
Lists all available services asynchronously.
public Task<List<string>> ListServicesAsync()
Returns
PublishEventAsync(string, CloudEvent, CancellationToken)
Publishes a CloudEvent to a topic asynchronously.
public Task<PublishResponse> PublishEventAsync(string topic, CloudEvent cloudevent, CancellationToken cancellationToken = default)
Parameters
topicstringThe topic name.
cloudeventCloudEventThe CloudEvent proto to publish.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<PublishResponse>
PublishResponse with success status.
PublishWithResultAsync(string, CloudEvent, string, TimeSpan?, string?, CancellationToken)
Publishes to a topic and waits for a correlated response on a reply topic.
Implements the request-reply pattern over pub/sub using correlation IDs.
Sets correlationid and replytopic as CloudEvent attributes
before publishing.
public Task<SubscribeResponse> PublishWithResultAsync(string topic, CloudEvent cloudevent, string replyTopic, TimeSpan? timeout = null, string? correlationId = null, CancellationToken cancellationToken = default)
Parameters
topicstringThe topic to publish the request to.
cloudeventCloudEventThe CloudEvent proto to publish.
replyTopicstringThe topic to listen for responses on.
timeoutTimeSpan?Maximum time to wait for a response (default: 30s).
correlationIdstringOptional correlation ID (auto-generated if null).
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<SubscribeResponse>
The correlated SubscribeResponse.
Exceptions
- TimeoutException
Thrown if no response arrives within the timeout.
QueryStateAsync(string, string, int, CancellationToken)
Gets all state key-value pairs asynchronously for a service.
public Task<List<StateItemDto>> QueryStateAsync(string service, string query, int limit = 0, CancellationToken cancellationToken = default)
Parameters
servicestringThe service name.
querystringThe Dapr JSON query string.
limitintMax results (0 = no limit).
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<List<StateItemDto>>
List of state items with key, value, etag.
SaveStateAsync(string, string, string, string?, bool, bool, CancellationToken)
Saves state and broadcasts a change event to subscribers asynchronously.
public Task<SaveStateResponse> SaveStateAsync(string service, string key, string value, string? etag = null, bool publishChange = false, bool includeValue = false, CancellationToken cancellationToken = default)
Parameters
servicestringThe service name.
keystringThe state key.
valuestringThe state value.
etagstringOptional etag for concurrency.
publishChangeboolIf true, a state.change event is published. Default false.
includeValueboolIf true, the value is included in the state change event payload. Only relevant when publishChange=true.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<SaveStateResponse>
SaveStateResponse with success status.
Subscribe(IEnumerable<string>?, IEnumerable<string>?, IEnumerable<string>?, CancellationToken)
Subscribes to events from specified services and topics.
public AsyncServerStreamingCall<SubscribeResponse> Subscribe(IEnumerable<string>? services = null, IEnumerable<string>? topics = null, IEnumerable<string>? eventTypes = null, CancellationToken cancellationToken = default)
Parameters
servicesIEnumerable<string>List of service names to subscribe to (empty for all).
topicsIEnumerable<string>List of topics to subscribe to (empty for all).
eventTypesIEnumerable<string>List of event types to subscribe to (empty for all).
cancellationTokenCancellationTokenCancellation token.
Returns
- AsyncServerStreamingCall<SubscribeResponse>
The async call handle. Dispose to cancel subscription.
SubscribeAsync(IStreamEventHandler, IEnumerable<string>?, IEnumerable<string>?, IEnumerable<string>?, CancellationToken)
Subscribes to events with a handler callback.
public Task SubscribeAsync(IStreamEventHandler handler, IEnumerable<string>? services = null, IEnumerable<string>? topics = null, IEnumerable<string>? eventTypes = null, CancellationToken cancellationToken = default)
Parameters
handlerIStreamEventHandlerHandler to receive events.
servicesIEnumerable<string>Optional service filter.
topicsIEnumerable<string>Optional topic filter.
eventTypesIEnumerable<string>Optional event type filter.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task that completes when subscription is cancelled.
SubscribeToTopic(string, CancellationToken)
Subscribes to a pub/sub topic and streams events.
public AsyncServerStreamingCall<SubscribeResponse> SubscribeToTopic(string topic, CancellationToken cancellationToken = default)
Parameters
topicstringThe topic name.
cancellationTokenCancellationTokenCancellation token.
Returns
- AsyncServerStreamingCall<SubscribeResponse>
Async streaming call for SubscribeResponse. Dispose to cancel.
TryGetMember(GetMemberBinder, out object?)
Dynamic property access returns a ServiceClient for the named service.
public override bool TryGetMember(GetMemberBinder binder, out object? result)
Parameters
binderGetMemberBinderresultobject
Returns
UnsubscribeFromTopicAsync(string, CancellationToken)
Unsubscribes from a pub/sub topic.
public Task<UnsubscribeResponse> UnsubscribeFromTopicAsync(string subscriptionId, CancellationToken cancellationToken = default)
Parameters
subscriptionIdstringThe subscription ID to cancel.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<UnsubscribeResponse>
UnsubscribeResponse with success status.