mirror of https://github.com/dapr/docs.git
Modernized example for binding outputs in .NET
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
This commit is contained in:
parent
fb3f24c050
commit
e7ca832c8c
|
|
@ -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.Serivces.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 %}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue