Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks;
using ControllerSample;
using Dapr;
using Dapr.Client;
Expand Down Expand Up @@ -40,7 +40,7 @@ public async Task GetConfiguration([FromRoute] string configStore, [FromRoute] s

foreach (var item in configItems.Items)
{
logger.LogInformation($"Got configuration item:\nKey: {item.Key}\nValue: {item.Value}\nVersion: {item.Version}");
logger.LogInformation($"Got configuration item:\nKey: {item.Key}\nValue: {item.Value.Value}\nVersion: {item.Value.Version}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/Client/ConfigurationApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var configItems = await client.GetConfiguration(configStore, new List<string>()

foreach (var item in configItems.Items)
{
logger.LogInformation($"Got configuration item:\nKey: {item.Key}\nValue: {item.Value}\nVersion: {item.Version}");
logger.LogInformation($"Got configuration item:\nKey: {item.Key}\nValue: {item.Value.Value}\nVersion: {item.Value.Version}");
}
```

Expand All @@ -51,7 +51,7 @@ try
foreach (var item in items)
{
id = subscribeConfigurationResponse.Id;
data[item.Key] = item.Value;
data[item.Key] = item.Value.Value;
}
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ You should see the following output from the application:
== APP == info: ConfigurationApi.Controllers.ConfigurationController[0]
== APP == Got configuration item:
== APP == Key: withdrawVersion
== APP == Value: v2
== APP == Value: v1
== APP == Version: 1
```

Expand Down
9 changes: 1 addition & 8 deletions src/Dapr.Client/ConfigurationItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@ public class ConfigurationItem
/// <summary>
/// Constructor for a ConfigurationItem.
/// </summary>
/// <param name="key">The key of the configuration item.</param>
/// <param name="value">The value of the configuration item.</param>
/// <param name="version">The version of the fetched item.</param>
/// <param name="metadata">The metadata associated with the request.</param>
public ConfigurationItem(string key, string value, string version, IReadOnlyDictionary<string, string> metadata)
public ConfigurationItem(string value, string version, IReadOnlyDictionary<string, string> metadata)
{
Key = key;
Value = value;
Version = version;
Metadata = metadata;
}

/// <summary>
/// The name of the configuration item.
/// </summary>
public string Key { get; }

/// <summary>
/// The value of the configuration item.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Dapr.Client/ConfigurationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace Dapr.Client
/// <summary>
/// Abstraction around a configuration source.
/// </summary>
public abstract class ConfigurationSource : IAsyncEnumerable<IEnumerable<ConfigurationItem>>
public abstract class ConfigurationSource : IAsyncEnumerable<IDictionary<string, ConfigurationItem>>
{
/// <summary>
/// The Id associated with this configuration source.
/// </summary>
public abstract string Id { get; }

/// <inheritdoc/>
public abstract IAsyncEnumerator<IEnumerable<ConfigurationItem>> GetAsyncEnumerator(CancellationToken cancellationToken = default);
public abstract IAsyncEnumerator<IDictionary<string, ConfigurationItem>> GetAsyncEnumerator(CancellationToken cancellationToken = default);
}
}
6 changes: 2 additions & 4 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,11 +1175,9 @@ public async override Task<GetConfigurationResponse> GetConfiguration(
throw new DaprException("GetConfiguration operation failed: the Dapr endpoint indicated a failure. See InnerException for details.", ex);
}

var listResponse = response.Items
.Select(i => new ConfigurationItem(i.Key, i.Value, i.Version, i.Metadata))
.ToList();
var responseItems = response.Items.ToDictionary(item => item.Key, item => new ConfigurationItem(item.Value.Value, item.Value.Version, item.Value.Metadata));

return new GetConfigurationResponse(listResponse);
return new GetConfigurationResponse(responseItems);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/Dapr.Client/DaprSubscribeConfigurationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal DaprSubscribeConfigurationSource(AsyncServerStreamingCall<Autogenerated
/// <inheritdoc/>
public override string Id => id;

public override IAsyncEnumerator<IEnumerable<ConfigurationItem>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
public override IAsyncEnumerator<IDictionary<string, ConfigurationItem>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return new DaprSubscribeConfigurationEnumerator(call, streamId => setIdIfNullOrEmpty(streamId), cancellationToken);
}
Expand All @@ -52,7 +52,7 @@ private void setIdIfNullOrEmpty(string id)
}
}

internal class DaprSubscribeConfigurationEnumerator : IAsyncEnumerator<IEnumerable<ConfigurationItem>>
internal class DaprSubscribeConfigurationEnumerator : IAsyncEnumerator<IDictionary<string, ConfigurationItem>>
{
private AsyncServerStreamingCall<Autogenerated.SubscribeConfigurationResponse> call;
private Action<string> idCallback;
Expand All @@ -69,15 +69,15 @@ internal DaprSubscribeConfigurationEnumerator(
}

/// <inheritdoc/>
public IEnumerable<ConfigurationItem> Current
public IDictionary<string, ConfigurationItem> Current
{
get
{
var current = call.ResponseStream.Current;
if (current != null)
{
idCallback(current.Id);
return current.Items.Select(item => new ConfigurationItem(item.Key, item.Value, item.Version, item.Metadata));
return current.Items.ToDictionary(item => item.Key, item => new ConfigurationItem(item.Value.Value, item.Value.Version, item.Value.Metadata));
}
return null;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Dapr.Client/GetConfigurationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ namespace Dapr.Client
/// </summary>
public class GetConfigurationResponse
{
private readonly IReadOnlyList<ConfigurationItem> items;
private readonly IReadOnlyDictionary<string, ConfigurationItem> configMap;

/// <summary>
/// Constructor for a GetConfigurationResponse.
/// </summary>
/// <param name="items">The items that were returned in the GetConfiguration call.</param>
public GetConfigurationResponse(IReadOnlyList<ConfigurationItem> items)
/// <param name="configMap">The map of keys to items that was returned in the GetConfiguration call.</param>
public GetConfigurationResponse(IReadOnlyDictionary<string, ConfigurationItem> configMap)
{
this.items = items;
this.configMap = configMap;
}

/// <summary>
/// The items returned in a GetConfiguration call. <see cref="ConfigurationItem"/>
/// The map of key to items returned in a GetConfiguration call. <see cref="ConfigurationItem"/>
/// </summary>
public IReadOnlyList<ConfigurationItem> Items
public IReadOnlyDictionary<string, ConfigurationItem> Items
{
get
{
return items;
return configMap;
}
}
}
Expand Down
47 changes: 41 additions & 6 deletions src/Dapr.Client/Protos/dapr/proto/common/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,53 @@ message StateOptions {
StateConsistency consistency = 2;
}

// TopicSubscription represents topic and metadata.
message TopicSubscription {
// Required. The name of the pubsub containing the topic below to subscribe to.
string pubsub_name = 1;

// Required. The name of topic which will be subscribed
string topic = 2;

// The optional properties used for this topic's subscription e.g. session id
map<string,string> metadata = 3;

// The optional routing rules to match against. In the gRPC interface, OnTopicEvent
// is still invoked but the matching path is sent in the TopicEventRequest.
TopicRoutes routes = 5;

// The optional dead letter queue for this topic to send events to.
string dead_letter_topic = 6;
}

message TopicRoutes {
// The list of rules for this topic.
repeated TopicRule rules = 1;

// The default path for this topic.
string default = 2;
}

message TopicRule {
// The optional CEL expression used to match the event.
// If the match is not specified, then the route is considered
// the default.
string match = 1;

// The path used to identify matches for this subscription.
// This value is passed in TopicEventRequest and used by OnTopicEvent to "switch"
// inside the handler.
string path = 2;
}

// ConfigurationItem represents all the configuration with its name(key).
message ConfigurationItem {
// Required. The name of configuration item
string key = 1;

// Required. The value of configuration item.
string value = 2;
string value = 1;

// Version is response only and cannot be fetched. Store is not expected to keep all versions available
string version = 3;
string version = 2;

// the metadata which will be passed to/from configuration store component.
map<string,string> metadata = 4;
map<string,string> metadata = 3;
}
52 changes: 12 additions & 40 deletions src/Dapr.Client/Protos/dapr/proto/dapr/v1/appcallback.proto
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ service AppCallback {
rpc OnBindingEvent(BindingEventRequest) returns (BindingEventResponse) {}
}

// AppCallbackHealthCheck V1 is an optional extension to AppCallback V1 to implement
// the HealthCheck method.
service AppCallbackHealthCheck {
// Health check.
rpc HealthCheck(google.protobuf.Empty) returns (HealthCheckResponse) {}
}

// TopicEventRequest message is compatible with CloudEvent spec v1.0
// https://github.com/cloudevents/spec/blob/v1.0/spec.md
message TopicEventRequest {
Expand Down Expand Up @@ -143,50 +150,15 @@ message BindingEventResponse {
// ListTopicSubscriptionsResponse is the message including the list of the subscribing topics.
message ListTopicSubscriptionsResponse {
// The list of topics.
repeated TopicSubscription subscriptions = 1;
}

// TopicSubscription represents topic and metadata.
message TopicSubscription {
// Required. The name of the pubsub containing the topic below to subscribe to.
string pubsub_name = 1;

// Required. The name of topic which will be subscribed
string topic = 2;

// The optional properties used for this topic's subscription e.g. session id
map<string,string> metadata = 3;

// The optional routing rules to match against. In the gRPC interface, OnTopicEvent
// is still invoked but the matching path is sent in the TopicEventRequest.
TopicRoutes routes = 5;

// The optional dead letter queue for this topic to send events to.
string dead_letter_topic = 6;
}

message TopicRoutes {
// The list of rules for this topic.
repeated TopicRule rules = 1;

// The default path for this topic.
string default = 2;
}

message TopicRule {
// The optional CEL expression used to match the event.
// If the match is not specified, then the route is considered
// the default.
string match = 1;

// The path used to identify matches for this subscription.
// This value is passed in TopicEventRequest and used by OnTopicEvent to "switch"
// inside the handler.
string path = 2;
repeated common.v1.TopicSubscription subscriptions = 1;
}

// ListInputBindingsResponse is the message including the list of input bindings.
message ListInputBindingsResponse {
// The list of input bindings.
repeated string bindings = 1;
}

// HealthCheckResponse is the message with the response to the health check.
// This message is currently empty as used as placeholder.
message HealthCheckResponse {}
9 changes: 5 additions & 4 deletions src/Dapr.Client/Protos/dapr/proto/dapr/v1/dapr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ service Dapr {
// UnSubscribeConfiguration unsubscribe the subscription of configuration
rpc UnsubscribeConfigurationAlpha1(UnsubscribeConfigurationRequest) returns (UnsubscribeConfigurationResponse) {}

// Distributed Lock API
// A non-blocking method trying to get a lock with ttl.
// TryLockAlpha1 tries to get a lock with an expiry.
rpc TryLockAlpha1(TryLockRequest)returns (TryLockResponse) {}

// UnlockAlpha1 unlocks a lock.
rpc UnlockAlpha1(UnlockRequest)returns (UnlockResponse) {}

// Gets metadata of the sidecar
Expand Down Expand Up @@ -479,6 +479,7 @@ message RegisteredComponents {
string name = 1;
string type = 2;
string version = 3;
repeated string capabilities = 4;
}

message SetMetadataRequest {
Expand All @@ -503,7 +504,7 @@ message GetConfigurationRequest {
// GetConfigurationResponse is the response conveying the list of configuration values.
// It should be the FULL configuration of specified application which contains all of its configuration items.
message GetConfigurationResponse {
repeated common.v1.ConfigurationItem items = 1;
map<string, common.v1.ConfigurationItem> items = 1;
}

// SubscribeConfigurationRequest is the message to get a list of key-value configuration from specified configuration store.
Expand Down Expand Up @@ -534,7 +535,7 @@ message SubscribeConfigurationResponse {
string id = 1;

// The list of items containing configuration values
repeated common.v1.ConfigurationItem items = 2;
map<string, common.v1.ConfigurationItem> items = 2;
}

message UnsubscribeConfigurationResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/Dapr.Client/SubscribeConfigurationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public string Id
/// <summary>
/// Get the <see cref="ConfigurationSource"/> that is used to read the actual subscribed configuration data.
/// </summary>
public IAsyncEnumerable<IEnumerable<ConfigurationItem>> Source => source;
public IAsyncEnumerable<IDictionary<string, ConfigurationItem>> Source => source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private async Task LoadAsync()
foreach (var item in items)
{
id = subscribeConfigurationResponse.Id;
data[item.Key] = item.Value;
data[item.Key] = item.Value.Value;
}
Data = data;
// Whenever we get an update, make sure to update the reloadToken.
Expand All @@ -118,7 +118,7 @@ private async Task LoadAsync()
var getConfigurationResponse = await daprClient.GetConfiguration(store, keys, metadata, cts.Token);
foreach (var item in getConfigurationResponse.Items)
{
Set(item.Key, item.Value);
Set(item.Key, item.Value.Value);
}
}
}
Expand Down
Loading