-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: MregXN <[email protected]>
- Loading branch information
Showing
2 changed files
with
19 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Dapr.Client; | ||
|
||
var baseURL = (Environment.GetEnvironmentVariable("BASE_URL") ?? "http://localhost") + ":" + (Environment.GetEnvironmentVariable("DAPR_HTTP_PORT") ?? "3500"); | ||
using var client = new DaprClientBuilder().Build(); | ||
|
||
var client = new HttpClient(); | ||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); | ||
// Adding app id as part of the header | ||
client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor"); | ||
|
||
for (int i = 1; i <= 20; i++) { | ||
var order = new Order(i); | ||
var orderJson = JsonSerializer.Serialize<Order>(order); | ||
var content = new StringContent(orderJson, Encoding.UTF8, "application/json"); | ||
for (int i = 1; i <= 20; i++) | ||
{ | ||
var data = new { orderId = i }; | ||
|
||
var cts = new CancellationTokenSource(); | ||
Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) => cts.Cancel(); | ||
// Invoking a service | ||
var response = await client.PostAsync($"{baseURL}/orders", content); | ||
Console.WriteLine("Order passed: " + order); | ||
await client.InvokeMethodAsync<object>( | ||
"order-processor", | ||
"orders", | ||
data, | ||
cts.Token | ||
); | ||
Console.WriteLine("Order passed: " + i); | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(1)); | ||
} | ||
|
||
public record Order([property: JsonPropertyName("orderId")] int OrderId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters