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>
|
/// <summary>
|
||||||
/// Invokes an output binding.
|
/// Invokes an output binding.
|
||||||
/// </summary>
|
/// </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="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="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>
|
/// <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>
|
/// <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,
|
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,
|
Dictionary<string, string> metadata = default,
|
||||||
CancellationToken cancellationToken = default);
|
CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
|
@ -59,7 +79,7 @@ namespace Dapr.Client
|
||||||
public abstract Task InvokeMethodAsync(
|
public abstract Task InvokeMethodAsync(
|
||||||
string appId,
|
string appId,
|
||||||
string methodName,
|
string methodName,
|
||||||
Dapr.Client.Http.HTTPExtension httpExtension = default,
|
Dapr.Client.Http.HTTPExtension httpExtension = default,
|
||||||
CancellationToken cancellationToken = default);
|
CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -77,22 +77,58 @@ namespace Dapr.Client
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region InvokeBinding Apis
|
#region InvokeBinding Apis
|
||||||
public override async Task InvokeBindingAsync<TContent>(
|
|
||||||
string name,
|
/// <inheritdoc/>
|
||||||
TContent content,
|
public override async Task InvokeBindingAsync<TRequest>(
|
||||||
Dictionary<string, string> metadata = default,
|
string name,
|
||||||
CancellationToken cancellationToken = default)
|
string operation,
|
||||||
|
TRequest data,
|
||||||
|
Dictionary<string, string> metadata = default,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ArgumentVerifier.ThrowIfNullOrEmpty(name, nameof(name));
|
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,
|
||||||
|
string operation,
|
||||||
|
TContent data,
|
||||||
|
Dictionary<string, string> metadata = default,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
var envelope = new Autogenerated.InvokeBindingRequest()
|
var envelope = new Autogenerated.InvokeBindingRequest()
|
||||||
{
|
{
|
||||||
Name = name,
|
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)
|
if (metadata != null)
|
||||||
|
|
@ -100,7 +136,7 @@ namespace Dapr.Client
|
||||||
envelope.Metadata.Add(metadata);
|
envelope.Metadata.Add(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.MakeGrpcCallHandleError(
|
return await this.MakeGrpcCallHandleError(
|
||||||
(options) =>
|
(options) =>
|
||||||
{
|
{
|
||||||
return client.InvokeBindingAsync(envelope, options);
|
return client.InvokeBindingAsync(envelope, options);
|
||||||
|
|
@ -581,7 +617,7 @@ namespace Dapr.Client
|
||||||
{
|
{
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
var bytes = JsonSerializer.SerializeToUtf8Bytes(data, options);
|
var bytes = JsonSerializer.SerializeToUtf8Bytes(data, options);
|
||||||
return ByteString.CopyFrom(bytes);
|
return ByteString.CopyFrom(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ service Dapr {
|
||||||
rpc PublishEvent(PublishEventRequest) returns (google.protobuf.Empty) {}
|
rpc PublishEvent(PublishEventRequest) returns (google.protobuf.Empty) {}
|
||||||
|
|
||||||
// Invokes binding data to specific output bindings
|
// Invokes binding data to specific output bindings
|
||||||
rpc InvokeBinding(InvokeBindingRequest) returns (google.protobuf.Empty) {}
|
rpc InvokeBinding(InvokeBindingRequest) returns (InvokeBindingResponse) {}
|
||||||
|
|
||||||
// Gets secrets from secret stores.
|
// Gets secrets from secret stores.
|
||||||
rpc GetSecret(GetSecretRequest) returns (GetSecretResponse) {}
|
rpc GetSecret(GetSecretRequest) returns (GetSecretResponse) {}
|
||||||
|
|
@ -121,6 +121,18 @@ message InvokeBindingRequest {
|
||||||
// have a default time to live. The message ttl overrides any value
|
// have a default time to live. The message ttl overrides any value
|
||||||
// in the binding definition.
|
// in the binding definition.
|
||||||
map<string,string> metadata = 3;
|
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.
|
// GetSecretRequest is the message to get secret from secret store.
|
||||||
|
|
@ -140,4 +152,4 @@ message GetSecretResponse {
|
||||||
// data is the secret value. Some secret store, such as kubernetes secret
|
// data is the secret value. Some secret store, such as kubernetes secret
|
||||||
// store, can save multiple secrets for single secret key.
|
// store, can save multiple secrets for single secret key.
|
||||||
map<string, string> data = 1;
|
map<string, string> data = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Dapr.Client.Test
|
||||||
metadata.Add("key1", "value1");
|
metadata.Add("key1", "value1");
|
||||||
metadata.Add("key2", "value2");
|
metadata.Add("key2", "value2");
|
||||||
var invokeRequest = new InvokeRequest() { RequestParameter = "Hello " };
|
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
|
// Get Request and validate
|
||||||
httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
|
httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue