diff --git a/daprdocs/content/en/developing-applications/building-blocks/configuration/howto-manage-configuration.md b/daprdocs/content/en/developing-applications/building-blocks/configuration/howto-manage-configuration.md index ed40d0bbb..fe42916e4 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/configuration/howto-manage-configuration.md +++ b/daprdocs/content/en/developing-applications/building-blocks/configuration/howto-manage-configuration.md @@ -37,7 +37,7 @@ redis-cli -p 6379 Save a configuration item: ``` -SET orderId "100||1" +MSET orderId1 "101||1" orderId2 "102||1" ``` ### Configure a Dapr configuration store @@ -48,7 +48,7 @@ Save the following component file, for example to the [default components folder apiVersion: dapr.io/v1alpha1 kind: Component metadata: - name: configurationstore + name: configstore spec: type: configuration.redis metadata: @@ -62,20 +62,75 @@ spec: Using your [favorite language](https://grpc.io/docs/languages/), create a Dapr gRPC client from the [Dapr proto](https://github.com/dapr/dapr/blob/master/dapr/proto/runtime/v1/dapr.proto). -{{< tabs Dotnet Java Python Javascript >}} +{{< tabs Dotnet Java Python>}} {{% codetab %}} ```csharp +//dependencies +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Dapr.Client; -var call = client.GetConfigurationAlpha1(new GetConfigurationRequest { StoreName = "redisconfigstore", Keys = new String[]{"myconfig"} }); +//code +namespace ConfigurationApi +{ + public class Program + { + private static readonly string CONFIG_STORE_NAME = "configstore"; + + [Obsolete] + public static async Task Main(string[] args) + { + using var client = new DaprClientBuilder().Build(); + var configuration = await client.GetConfiguration(CONFIG_STORE_NAME, new List() { "orderId1", "orderId2" }); + Console.WriteLine($"Got key=\n{configuration[0].Key} -> {configuration[0].Value}\n{configuration[1].Key} -> {configuration[1].Value}"); + } + } +} +``` + +Navigate to the directory containing the above code and run the following command to launch the application along with a Dapr sidecar: + +```bash +dapr run --app-id orderprocessing --components-path ./components -- dotnet run ``` {{% /codetab %}} {{% codetab %}} ```java +//dependencies +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.DaprPreviewClient; +import io.dapr.client.domain.ConfigurationItem; +import io.dapr.client.domain.GetConfigurationRequest; +import io.dapr.client.domain.SubscribeConfigurationRequest; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; -Dapr.ServiceBlockingStub stub = Dapr.newBlockingStub(channel); -stub.GetConfigurationAlpha1(new GetConfigurationRequest{ StoreName = "redisconfigstore", Keys = new String[]{"myconfig"} }); +//code +private static final String CONFIG_STORE_NAME = "configstore"; + +public static void main(String[] args) throws Exception { + try (DaprPreviewClient client = (new DaprClientBuilder()).buildPreviewClient()) { + List keys = new ArrayList<>(); + keys.add("orderId1"); + keys.add("orderId2"); + GetConfigurationRequest req = new GetConfigurationRequest(CONFIG_STORE_NAME, keys); + try { + Mono> items = client.getConfiguration(req); + items.block().forEach(ConfigurationClient::print); + } catch (Exception ex) { + System.out.println(ex.getMessage()); + } + } +} +``` + +Navigate to the directory containing the above code and run the following command to launch the application along with a Dapr sidecar: + +```bash +dapr run --app-id orderprocessing --components-path ./components mvn spring-boot:run ``` {{% /codetab %}} @@ -85,18 +140,18 @@ stub.GetConfigurationAlpha1(new GetConfigurationRequest{ StoreName = "redisconfi from dapr.clients import DaprClient #code with DaprClient() as d: - storeName = 'configurationstore' - key = 'orderId' + CONFIG_STORE_NAME = 'configstore' + keys = ['orderId1', 'orderId2'] #Startup time for dapr d.wait(20) - configuration = d.get_configuration(store_name=storeName, keys=[key], config_metadata={}) + configuration = d.get_configuration(store_name=CONFIG_STORE_NAME, keys=[keys], config_metadata={}) print(f"Got key={configuration.items[0].key} value={configuration.items[0].value} version={configuration.items[0].version}") ``` Navigate to the directory containing the above code and run the following command to launch the application along with a Dapr sidecar: ```bash -dapr run --app-id orderprocessing python3 OrderProcessingService.py +dapr run --app-id orderprocessing --components-path ./components python3 OrderProcessingService.py ``` {{% /codetab %}}