mirror of https://github.com/dapr/docs.git
Merge branch 'v1.15' into pubsub-topics-dotnet
This commit is contained in:
commit
42928bd5c9
|
|
@ -110,40 +110,30 @@ The code examples below leverage Dapr SDKs to invoke the output bindings endpoin
|
|||
|
||||
{{% codetab %}}
|
||||
|
||||
Here's an example of using a console app with top-level statements in .NET 6+:
|
||||
|
||||
```csharp
|
||||
//dependencies
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Dapr.Client;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
|
||||
//code
|
||||
namespace EventService
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDaprClient();
|
||||
var app = builder.Build();
|
||||
|
||||
const string BINDING_NAME = "checkout";
|
||||
const string BINDING_OPERATION = "create";
|
||||
|
||||
var random = new Random();
|
||||
using var daprClient = app.Services.GetRequiredService<DaprClient>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
string BINDING_NAME = "checkout";
|
||||
string BINDING_OPERATION = "create";
|
||||
while(true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(5000);
|
||||
Random random = new Random();
|
||||
int orderId = random.Next(1,1000);
|
||||
using var client = new DaprClientBuilder().Build();
|
||||
//Using Dapr SDK to invoke output binding
|
||||
await client.InvokeBindingAsync(BINDING_NAME, BINDING_OPERATION, orderId);
|
||||
Console.WriteLine("Sending message: " + orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
var orderId = random.Next(1, 1000);
|
||||
await client.InvokeBindingAsync(BINDING_NAME, BINDING_OPERATION, orderId);
|
||||
Console.WriteLine($"Sending message: {orderId}");
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
|
|
|||
|
|
@ -119,28 +119,35 @@ Below are code examples that leverage Dapr SDKs to demonstrate an input binding.
|
|||
|
||||
{{% codetab %}}
|
||||
|
||||
The following example demonstrates how to configure an input binding using ASP.NET Core controllers.
|
||||
|
||||
```csharp
|
||||
//dependencies
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
//code
|
||||
namespace CheckoutService.controller
|
||||
namespace CheckoutService.controller;
|
||||
|
||||
[ApiController]
|
||||
public sealed class CheckoutServiceController : ControllerBase
|
||||
{
|
||||
[ApiController]
|
||||
public class CheckoutServiceController : Controller
|
||||
[HttpPost("/checkout")]
|
||||
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||
{
|
||||
[HttpPost("/checkout")]
|
||||
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||
{
|
||||
Console.WriteLine("Received Message: " + orderId);
|
||||
return "CID" + orderId;
|
||||
}
|
||||
Console.WriteLine($"Received Message: {orderId}");
|
||||
return $"CID{orderId}";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The following example demonstrates how to configure the same input binding using a minimal API approach:
|
||||
```csharp
|
||||
app.MapPost("checkout", ([FromBody] int orderId) =>
|
||||
{
|
||||
Console.WriteLine($"Received Message: {orderId}");
|
||||
return $"CID{orderId}"
|
||||
});
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
|
|
|||
|
|
@ -76,27 +76,21 @@ The following example shows how to get a saved configuration item using the Dapr
|
|||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
//dependencies
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Dapr.Client;
|
||||
|
||||
//code
|
||||
namespace ConfigurationApi
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static readonly string CONFIG_STORE_NAME = "configstore";
|
||||
const string CONFIG_STORE_NAME = "configstore";
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
using var client = new DaprClientBuilder().Build();
|
||||
var configuration = await client.GetConfiguration(CONFIG_STORE_NAME, new List<string>() { "orderId1", "orderId2" });
|
||||
Console.WriteLine($"Got key=\n{configuration[0].Key} -> {configuration[0].Value}\n{configuration[1].Key} -> {configuration[1].Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDaprClient();
|
||||
var app = builder.Build();
|
||||
|
||||
using var client = app.Services.GetRequiredServices<DaprClient>();
|
||||
|
||||
var configuration = await client.GetConfiguration(CONFIG_STORE_NAME, [ "orderId1", "orderId2" ]);
|
||||
Console.WriteLine($"Got key=\n{configuration[0].Key} -> {configuration[0].Value}\n{configuration[1].Key} -> {configuration[1].Value}");
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
|
@ -261,13 +255,19 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Dapr.Client;
|
||||
using System.Text.Json;
|
||||
|
||||
const string DAPR_CONFIGURATION_STORE = "configstore";
|
||||
var CONFIGURATION_ITEMS = new List<string> { "orderId1", "orderId2" };
|
||||
var client = new DaprClientBuilder().Build();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDaprClient();
|
||||
var app = builder.Build();
|
||||
|
||||
var client = app.Services.GetRequiredService<DaprClient>();
|
||||
|
||||
// Subscribe for configuration changes
|
||||
SubscribeConfigurationResponse subscribe = await client.SubscribeConfiguration(DAPR_CONFIGURATION_STORE, CONFIGURATION_ITEMS);
|
||||
var subscribe = await client.SubscribeConfiguration(DAPR_CONFIGURATION_STORE, CONFIGURATION_ITEMS);
|
||||
|
||||
// Print configuration changes
|
||||
await foreach (var items in subscribe.Source)
|
||||
|
|
@ -279,7 +279,7 @@ await foreach (var items in subscribe.Source)
|
|||
subscriptionId = subscribe.Id;
|
||||
continue;
|
||||
}
|
||||
var cfg = System.Text.Json.JsonSerializer.Serialize(items);
|
||||
var cfg = JsonSerializer.Serialize(items);
|
||||
Console.WriteLine("Configuration update " + cfg);
|
||||
}
|
||||
```
|
||||
|
|
@ -303,40 +303,23 @@ using Dapr.Extensions.Configuration;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace ConfigurationApi
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Starting application.");
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
Console.WriteLine("Closing application.");
|
||||
}
|
||||
Console.WriteLine("Starting application.");
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
/// <summary>
|
||||
/// Creates WebHost Builder.
|
||||
/// </summary>
|
||||
/// <param name="args">Arguments.</param>
|
||||
/// <returns>Returns IHostbuilder.</returns>
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
{
|
||||
var client = new DaprClientBuilder().Build();
|
||||
return Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
{
|
||||
// Get the initial value and continue to watch it for changes.
|
||||
config.AddDaprConfigurationStore("configstore", new List<string>() { "orderId1","orderId2" }, client, TimeSpan.FromSeconds(20));
|
||||
config.AddStreamingDaprConfigurationStore("configstore", new List<string>() { "orderId1","orderId2" }, client, TimeSpan.FromSeconds(20));
|
||||
// Unlike most other situations, we build a `DaprClient` here using its factory because we cannot rely on `IConfiguration`
|
||||
// or other injected services to configure it because we haven't yet built the DI container.
|
||||
var client = new DaprClientBuilder().Build();
|
||||
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
// In a real-world application, you'd also add the following line to register the `DaprClient` with the DI container so
|
||||
// it can be injected into other services. In this demonstration, it's not necessary as we're not injecting it anywhere.
|
||||
// builder.Services.AddDaprClient();
|
||||
|
||||
// Get the initial value and continue to watch it for changes
|
||||
builder.Configuration.AddDaprConfigurationStore("configstore", new List<string>() { "orderId1","orderId2" }, client, TimeSpan.FromSeconds(20));
|
||||
builder.Configuration.AddStreamingDaprConfigurationStore("configstore", new List<string>() { "orderId1","orderId2" }, client, TimeSpan.FromSeconds(20));
|
||||
|
||||
await builder.Build().RunAsync();
|
||||
Console.WriteLine("Closing application.");
|
||||
```
|
||||
|
||||
Navigate to the directory containing the above code, then run the following command to launch both a Dapr sidecar and the subscriber application:
|
||||
|
|
@ -524,29 +507,23 @@ Following are the code examples showing how you can unsubscribe to configuration
|
|||
{{< tabs ".NET" Java Python Go JavaScript "HTTP API (BASH)" "HTTP API (Powershell)">}}
|
||||
|
||||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Dapr.Client;
|
||||
|
||||
const string DAPR_CONFIGURATION_STORE = "configstore";
|
||||
var client = new DaprClientBuilder().Build();
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
builder.Services.AddDaprClient();
|
||||
var app = builder.Build();
|
||||
|
||||
// Unsubscribe to config updates and exit the app
|
||||
async Task unsubscribe(string subscriptionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
await client.UnsubscribeConfiguration(DAPR_CONFIGURATION_STORE, subscriptionId);
|
||||
Console.WriteLine("App unsubscribed from config changes");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error unsubscribing from config updates: " + ex.Message);
|
||||
}
|
||||
}
|
||||
const string DAPR_CONFIGURATION_STORE = "configstore";
|
||||
const string SubscriptionId = "abc123"; //Replace with the subscription identifier to unsubscribe from
|
||||
var client = app.Services.GetRequiredService<DaprClient>();
|
||||
|
||||
await client.UnsubscribeConfiguration(DAPR_CONFIGURATION_STORE, SubscriptionId);
|
||||
Console.WriteLine("App unsubscribed from config changes");
|
||||
```
|
||||
{{% /codetab %}}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,32 +76,25 @@ Now that you've set up the local secret store, call Dapr to get the secrets from
|
|||
{{% codetab %}}
|
||||
|
||||
```csharp
|
||||
//dependencies
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Dapr.Client;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading;
|
||||
using System.Text.Json;
|
||||
|
||||
//code
|
||||
namespace EventService
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
string SECRET_STORE_NAME = "localsecretstore";
|
||||
using var client = new DaprClientBuilder().Build();
|
||||
//Using Dapr SDK to get a secret
|
||||
var secret = await client.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
||||
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace EventService;
|
||||
|
||||
const string SECRET_STORE_NAME = "localsecretstore";
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddDaprClient();
|
||||
var app = builder.Build();
|
||||
|
||||
//Resolve a DaprClient from DI
|
||||
var daprClient = app.Services.GetRequiredService<DaprClient>();
|
||||
|
||||
//Use the Dapr SDK to get a secret
|
||||
var secret = await daprClient.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
||||
|
||||
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
||||
```
|
||||
|
||||
{{% /codetab %}}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ apps:
|
|||
|
||||
#### Echo mock LLM component
|
||||
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yml) configures the echo LLM component.
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yaml) configures the echo LLM component.
|
||||
|
||||
```yml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
|
|
@ -215,7 +215,7 @@ apps:
|
|||
|
||||
#### Echo mock LLM component
|
||||
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yml) configures the echo LLM component.
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yaml) configures the echo LLM component.
|
||||
|
||||
```yml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
|
|
@ -345,7 +345,7 @@ apps:
|
|||
|
||||
#### Echo mock LLM component
|
||||
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components), the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yml) configures the echo mock LLM component.
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components), the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yaml) configures the echo mock LLM component.
|
||||
|
||||
```yml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
|
|
@ -475,7 +475,7 @@ apps:
|
|||
|
||||
#### Echo mock LLM component
|
||||
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yml) configures the echo LLM component.
|
||||
In [`conversation/components`](https://github.com/dapr/quickstarts/tree/master/conversation/components) directly of the quickstart, the [`conversation.yaml` file](https://github.com/dapr/quickstarts/tree/master/conversation/components/conversation.yaml) configures the echo LLM component.
|
||||
|
||||
```yml
|
||||
apiVersion: dapr.io/v1alpha1
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ The above example uses secrets as plain strings. It is recommended to use a secr
|
|||
| failover | N | Property to enabled failover configuration. Needs sentinalMasterName to be set. Defaults to `"false"` | `"true"`, `"false"`
|
||||
| sentinelMasterName | N | The sentinel master name. See [Redis Sentinel Documentation](https://redis.io/docs/manual/sentinel/) | `""`, `"127.0.0.1:6379"`
|
||||
| maxLenApprox | N | Maximum number of items inside a stream.The old entries are automatically evicted when the specified length is reached, so that the stream is left at a constant size. Defaults to unlimited. | `"10000"`
|
||||
| streamTTL | N | TTL duration for stream entries. Entries older than this duration will be evicted. This is an approximate value, as it's implemented using Redis stream's `MINID` trimming with the '~' modifier. The actual retention may include slightly more entries than strictly defined by the TTL, as Redis optimizes the trimming operation for efficiency by potentially keeping some additional entries. | `"30d"`
|
||||
|
||||
## Create a Redis instance
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue