mirror of https://github.com/dapr/dotnet-sdk.git
Update to sdk for changes in proto for bidirectional binding in runtime (#320)
* Update proto for bidirectional binding in runtime * move arg check Co-authored-by: LM <lemai>
This commit is contained in:
parent
f3b5c7db81
commit
041a2d1255
|
|
@ -36,15 +36,35 @@ namespace Dapr.Client
|
|||
/// <summary>
|
||||
/// Invokes an output binding.
|
||||
/// </summary>
|
||||
/// <typeparam name="TContent"></typeparam>
|
||||
/// <typeparam name="TRequest"></typeparam>
|
||||
/// <param name="name">The name of the binding to sent the event to.</param>
|
||||
/// <param name="content">The content of the event to send.</param>
|
||||
/// <param name="operation">The type of operation to perform on the binding.</param>
|
||||
/// <param name="data">The data of the event to send.</param>
|
||||
/// <param name="metadata">An open key/value pair that may be consumed by the binding component.</param>
|
||||
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
|
||||
/// <returns>A <see cref="Task" /> that will complete when the operation has completed.</returns>
|
||||
public abstract Task InvokeBindingAsync<TContent>(
|
||||
public abstract Task InvokeBindingAsync<TRequest>(
|
||||
string name,
|
||||
TContent content,
|
||||
string operation,
|
||||
TRequest data,
|
||||
Dictionary<string, string> metadata = default,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Invokes an output binding.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRequest">The type of the object for the data to send.</typeparam>
|
||||
/// <typeparam name="TResponse">The type of the object for the return value.</typeparam>
|
||||
/// <param name="name">The name of the binding to sent the event to.</param>
|
||||
/// <param name="operation">The type of operation to perform on the binding.</param>
|
||||
/// <param name="data">The data of the event to send.</param>
|
||||
/// <param name="metadata">An open key/value pair that may be consumed by the binding component.</param>
|
||||
/// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{T}" /> that will complete when the operation has completed.</returns>
|
||||
public abstract ValueTask<TResponse> InvokeBindingAsync<TRequest, TResponse>(
|
||||
string name,
|
||||
string operation,
|
||||
TRequest data,
|
||||
Dictionary<string, string> metadata = default,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,22 +77,58 @@ namespace Dapr.Client
|
|||
#endregion
|
||||
|
||||
#region InvokeBinding Apis
|
||||
public override async Task InvokeBindingAsync<TContent>(
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task InvokeBindingAsync<TRequest>(
|
||||
string name,
|
||||
string operation,
|
||||
TRequest data,
|
||||
Dictionary<string, string> metadata = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
|
||||
ArgumentVerifier.ThrowIfNullOrEmpty(operation, nameof(operation));
|
||||
|
||||
_ = await MakeInvokeBindingRequestAsync(name, operation, data, metadata, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async ValueTask<TResponse> InvokeBindingAsync<TRequest, TResponse>(
|
||||
string name,
|
||||
string operation,
|
||||
TRequest data,
|
||||
Dictionary<string, string> metadata = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
|
||||
ArgumentVerifier.ThrowIfNullOrEmpty(operation, nameof(operation));
|
||||
|
||||
InvokeBindingResponse response = await MakeInvokeBindingRequestAsync(name, operation, data, metadata, cancellationToken);
|
||||
return ConvertFromInvokeBindingResponse<TResponse>(response, this.jsonSerializerOptions);
|
||||
}
|
||||
|
||||
private static T ConvertFromInvokeBindingResponse<T>(InvokeBindingResponse response, JsonSerializerOptions options = null)
|
||||
{
|
||||
var responseData = response.Data.ToStringUtf8();
|
||||
return JsonSerializer.Deserialize<T>(responseData, options);
|
||||
}
|
||||
|
||||
private async Task<InvokeBindingResponse> MakeInvokeBindingRequestAsync<TContent>(
|
||||
string name,
|
||||
TContent content,
|
||||
string operation,
|
||||
TContent data,
|
||||
Dictionary<string, string> metadata = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
|
||||
|
||||
var envelope = new Autogenerated.InvokeBindingRequest()
|
||||
{
|
||||
Name = name,
|
||||
Operation = operation
|
||||
};
|
||||
|
||||
if (content != null)
|
||||
if (data != null)
|
||||
{
|
||||
envelope.Data = ConvertToByteStringAsync(content, this.jsonSerializerOptions);
|
||||
envelope.Data = ConvertToByteStringAsync(data, this.jsonSerializerOptions);
|
||||
}
|
||||
|
||||
if (metadata != null)
|
||||
|
|
@ -100,7 +136,7 @@ namespace Dapr.Client
|
|||
envelope.Metadata.Add(metadata);
|
||||
}
|
||||
|
||||
await this.MakeGrpcCallHandleError(
|
||||
return await this.MakeGrpcCallHandleError(
|
||||
(options) =>
|
||||
{
|
||||
return client.InvokeBindingAsync(envelope, options);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ service Dapr {
|
|||
rpc PublishEvent(PublishEventRequest) returns (google.protobuf.Empty) {}
|
||||
|
||||
// Invokes binding data to specific output bindings
|
||||
rpc InvokeBinding(InvokeBindingRequest) returns (google.protobuf.Empty) {}
|
||||
rpc InvokeBinding(InvokeBindingRequest) returns (InvokeBindingResponse) {}
|
||||
|
||||
// Gets secrets from secret stores.
|
||||
rpc GetSecret(GetSecretRequest) returns (GetSecretResponse) {}
|
||||
|
|
@ -121,6 +121,18 @@ message InvokeBindingRequest {
|
|||
// have a default time to live. The message ttl overrides any value
|
||||
// in the binding definition.
|
||||
map<string,string> metadata = 3;
|
||||
|
||||
// The name of the operation type for the binding to invoke
|
||||
string operation = 4;
|
||||
}
|
||||
|
||||
// InvokeBindingResponse is the message returned from an output binding invocation
|
||||
message InvokeBindingResponse {
|
||||
// The data which will be sent to output binding.
|
||||
bytes data = 1;
|
||||
|
||||
// The metadata returned from an external system
|
||||
map<string,string> metadata = 2;
|
||||
}
|
||||
|
||||
// GetSecretRequest is the message to get secret from secret store.
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Dapr.Client.Test
|
|||
metadata.Add("key1", "value1");
|
||||
metadata.Add("key2", "value2");
|
||||
var invokeRequest = new InvokeRequest() { RequestParameter = "Hello " };
|
||||
var task = daprClient.InvokeBindingAsync<InvokeRequest>("test", invokeRequest, metadata);
|
||||
var task = daprClient.InvokeBindingAsync<InvokeRequest>("test", "create", invokeRequest, metadata);
|
||||
|
||||
// Get Request and validate
|
||||
httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
|
||||
|
|
|
|||
Loading…
Reference in New Issue