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 %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
Here's an example of using a console app with top-level statements in .NET 6+:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
//dependencies
|
using System.Text;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
//code
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
namespace EventService
|
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
|
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||||
{
|
var orderId = random.Next(1, 1000);
|
||||||
static async Task Main(string[] args)
|
await client.InvokeBindingAsync(BINDING_NAME, BINDING_OPERATION, orderId);
|
||||||
{
|
Console.WriteLine($"Sending message: {orderId}");
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
|
||||||
|
|
@ -119,28 +119,35 @@ Below are code examples that leverage Dapr SDKs to demonstrate an input binding.
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
The following example demonstrates how to configure an input binding using ASP.NET Core controllers.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
//dependencies
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
//code
|
namespace CheckoutService.controller;
|
||||||
namespace CheckoutService.controller
|
|
||||||
|
[ApiController]
|
||||||
|
public sealed class CheckoutServiceController : ControllerBase
|
||||||
{
|
{
|
||||||
[ApiController]
|
[HttpPost("/checkout")]
|
||||||
public class CheckoutServiceController : Controller
|
public ActionResult<string> getCheckout([FromBody] int orderId)
|
||||||
{
|
{
|
||||||
[HttpPost("/checkout")]
|
Console.WriteLine($"Received Message: {orderId}");
|
||||||
public ActionResult<string> getCheckout([FromBody] int 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 %}}
|
{{% /codetab %}}
|
||||||
|
|
|
||||||
|
|
@ -76,27 +76,21 @@ The following example shows how to get a saved configuration item using the Dapr
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
//dependencies
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
|
|
||||||
//code
|
const string CONFIG_STORE_NAME = "configstore";
|
||||||
namespace ConfigurationApi
|
|
||||||
{
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
private static readonly string CONFIG_STORE_NAME = "configstore";
|
|
||||||
|
|
||||||
public static async Task Main(string[] args)
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
{
|
builder.Services.AddDaprClient();
|
||||||
using var client = new DaprClientBuilder().Build();
|
var app = builder.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}");
|
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 %}}
|
{{% /codetab %}}
|
||||||
|
|
@ -261,13 +255,19 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
const string DAPR_CONFIGURATION_STORE = "configstore";
|
const string DAPR_CONFIGURATION_STORE = "configstore";
|
||||||
var CONFIGURATION_ITEMS = new List<string> { "orderId1", "orderId2" };
|
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
|
// 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
|
// Print configuration changes
|
||||||
await foreach (var items in subscribe.Source)
|
await foreach (var items in subscribe.Source)
|
||||||
|
|
@ -279,7 +279,7 @@ await foreach (var items in subscribe.Source)
|
||||||
subscriptionId = subscribe.Id;
|
subscriptionId = subscribe.Id;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var cfg = System.Text.Json.JsonSerializer.Serialize(items);
|
var cfg = JsonSerializer.Serialize(items);
|
||||||
Console.WriteLine("Configuration update " + cfg);
|
Console.WriteLine("Configuration update " + cfg);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -303,40 +303,23 @@ using Dapr.Extensions.Configuration;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace ConfigurationApi
|
Console.WriteLine("Starting application.");
|
||||||
{
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Starting application.");
|
|
||||||
CreateHostBuilder(args).Build().Run();
|
|
||||||
Console.WriteLine("Closing application.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
// Unlike most other situations, we build a `DaprClient` here using its factory because we cannot rely on `IConfiguration`
|
||||||
/// Creates WebHost Builder.
|
// or other injected services to configure it because we haven't yet built the DI container.
|
||||||
/// </summary>
|
var client = new DaprClientBuilder().Build();
|
||||||
/// <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));
|
|
||||||
|
|
||||||
})
|
// In a real-world application, you'd also add the following line to register the `DaprClient` with the DI container so
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
// it can be injected into other services. In this demonstration, it's not necessary as we're not injecting it anywhere.
|
||||||
{
|
// builder.Services.AddDaprClient();
|
||||||
webBuilder.UseStartup<Startup>();
|
|
||||||
});
|
// 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:
|
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)">}}
|
{{< tabs ".NET" Java Python Go JavaScript "HTTP API (BASH)" "HTTP API (Powershell)">}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
|
|
||||||
const string DAPR_CONFIGURATION_STORE = "configstore";
|
var builder = WebApplication.CreateBuilder();
|
||||||
var client = new DaprClientBuilder().Build();
|
builder.Services.AddDaprClient();
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
// Unsubscribe to config updates and exit the app
|
const string DAPR_CONFIGURATION_STORE = "configstore";
|
||||||
async Task unsubscribe(string subscriptionId)
|
const string SubscriptionId = "abc123"; //Replace with the subscription identifier to unsubscribe from
|
||||||
{
|
var client = app.Services.GetRequiredService<DaprClient>();
|
||||||
try
|
|
||||||
{
|
await client.UnsubscribeConfiguration(DAPR_CONFIGURATION_STORE, SubscriptionId);
|
||||||
await client.UnsubscribeConfiguration(DAPR_CONFIGURATION_STORE, subscriptionId);
|
Console.WriteLine("App unsubscribed from config changes");
|
||||||
Console.WriteLine("App unsubscribed from config changes");
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Error unsubscribing from config updates: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,32 +76,25 @@ Now that you've set up the local secret store, call Dapr to get the secrets from
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
//dependencies
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
//code
|
namespace EventService;
|
||||||
namespace EventService
|
|
||||||
{
|
const string SECRET_STORE_NAME = "localsecretstore";
|
||||||
class Program
|
|
||||||
{
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
static async Task Main(string[] args)
|
builder.Services.AddDaprClient();
|
||||||
{
|
var app = builder.Build();
|
||||||
string SECRET_STORE_NAME = "localsecretstore";
|
|
||||||
using var client = new DaprClientBuilder().Build();
|
//Resolve a DaprClient from DI
|
||||||
//Using Dapr SDK to get a secret
|
var daprClient = app.Services.GetRequiredService<DaprClient>();
|
||||||
var secret = await client.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
|
||||||
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
//Use the Dapr SDK to get a secret
|
||||||
}
|
var secret = await daprClient.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
||||||
}
|
|
||||||
}
|
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ apps:
|
||||||
|
|
||||||
#### Echo mock LLM component
|
#### 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
|
```yml
|
||||||
apiVersion: dapr.io/v1alpha1
|
apiVersion: dapr.io/v1alpha1
|
||||||
|
|
@ -215,7 +215,7 @@ apps:
|
||||||
|
|
||||||
#### Echo mock LLM component
|
#### 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
|
```yml
|
||||||
apiVersion: dapr.io/v1alpha1
|
apiVersion: dapr.io/v1alpha1
|
||||||
|
|
@ -345,7 +345,7 @@ apps:
|
||||||
|
|
||||||
#### Echo mock LLM component
|
#### 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
|
```yml
|
||||||
apiVersion: dapr.io/v1alpha1
|
apiVersion: dapr.io/v1alpha1
|
||||||
|
|
@ -475,7 +475,7 @@ apps:
|
||||||
|
|
||||||
#### Echo mock LLM component
|
#### 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
|
```yml
|
||||||
apiVersion: dapr.io/v1alpha1
|
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"`
|
| 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"`
|
| 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"`
|
| 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
|
## Create a Redis instance
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue