diff --git a/docs/recipes/dapr.md b/docs/recipes/dapr.md index 4bebee0a..fc38f5e5 100644 --- a/docs/recipes/dapr.md +++ b/docs/recipes/dapr.md @@ -12,9 +12,14 @@ Getting started documentation for Dapr can be found [here](https://docs.dapr.io/ ## Sample Code -The sample code for document can be found [here](https://github.com/dotnet/tye/tree/master/samples/dapr). +There are two sample projects for the Dapr recipe [here](https://github.com/dotnet/tye/tree/master/samples/dapr). -This application has three services: +They demonstrate + +- Pub/Sub (The sample code associated with the instructions below.) +- Service Invocation + +The pub-sub sample application has three services: - A frontend application (`store`) - A products backend service (`products`) @@ -22,15 +27,15 @@ This application has three services: These services use a variety of Dapr's features: -- State Storate (`store`) +- State Storage (`store`) - Invoke (`store`, `products`) - Pub/Sub (`store`, `orders`) -You can find the Dapr component files [here](https://github.com/dotnet/tye/tree/master/samples/dapr/components). +You can find the Dapr component files for the sample project [here](https://github.com/dotnet/tye/tree/master/samples/dapr/pub-sub/components). ## Running the sample locally -To run this sample, simply go to the `samples/dapr` directory and run the following command: +To run this sample, simply go to the `samples/dapr/pub-sub` directory and run the following command: ```sh tye run @@ -65,7 +70,7 @@ Each application would need to be given a unique port to listen on, and launched Tye has built-in support that can make this more productive by: - Launching everything at once -- Automatically manging ports +- Automatically managing ports Tye's Dapr integration is activated in `tye.yaml` (seen below for this sample): diff --git a/samples/dapr/service-invocation/SentenceApp/SentenceApp.csproj b/samples/dapr/service-invocation/SentenceApp/SentenceApp.csproj index 8aeae316..0f8fc708 100644 --- a/samples/dapr/service-invocation/SentenceApp/SentenceApp.csproj +++ b/samples/dapr/service-invocation/SentenceApp/SentenceApp.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/samples/dapr/service-invocation/SentenceApp/Services/LowercaseServiceClient.cs b/samples/dapr/service-invocation/SentenceApp/Services/LowercaseServiceClient.cs index faffd48c..d1a46184 100644 --- a/samples/dapr/service-invocation/SentenceApp/Services/LowercaseServiceClient.cs +++ b/samples/dapr/service-invocation/SentenceApp/Services/LowercaseServiceClient.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; -using System.Net.Http; +using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; using Dapr.Client; -using Dapr.Client.Http; using Shared; namespace SentenceApp.Services @@ -28,18 +26,14 @@ namespace SentenceApp.Services public async Task Convert(string sentence) { // Using Dapr sidecar and service invocation building block - return await _daprClient.InvokeMethodAsync("lowercaseservice", "lowercase", new object(), new HTTPExtension() - { - QueryString = new Dictionary() - { - {"sentence", sentence} - }, - Verb = HTTPVerb.Get - }); + return await _daprClient.InvokeMethodAsync("lowercaseservice", "lowercase", new object(), + HttpInvocationOptions.UsingGet() + .WithQueryParam("sentence", sentence)); + // If you're using Tye alone (without dapr) //var responseMessage = await _client.GetAsync($"/lowercase?sentence={sentence}"); //var stream = await responseMessage.Content.ReadAsStreamAsync(); //return await JsonSerializer.DeserializeAsync(stream, _options); } } -} \ No newline at end of file +} diff --git a/samples/dapr/service-invocation/SentenceApp/Services/TitlecaseServiceClient.cs b/samples/dapr/service-invocation/SentenceApp/Services/TitlecaseServiceClient.cs index c1dc6bf2..87ae4381 100644 --- a/samples/dapr/service-invocation/SentenceApp/Services/TitlecaseServiceClient.cs +++ b/samples/dapr/service-invocation/SentenceApp/Services/TitlecaseServiceClient.cs @@ -1,9 +1,7 @@ -using System.Collections.Generic; -using System.Net.Http; +using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; using Dapr.Client; -using Dapr.Client.Http; using Shared; namespace SentenceApp.Services @@ -28,19 +26,14 @@ namespace SentenceApp.Services public async Task Convert(string sentence) { // Using Dapr sidecar and service invocation building block - return await _daprClient.InvokeMethodAsync("titlecaseservice", "titlecase", new object(), new HTTPExtension() - { - QueryString = new Dictionary() - { - {"sentence", sentence} - }, - Verb = HTTPVerb.Get - }); + return await _daprClient.InvokeMethodAsync("titlecaseservice", "titlecase", new object(), + HttpInvocationOptions.UsingGet() + .WithQueryParam("sentence", sentence)); - // If you're using Tye alone + // If you're using Tye alone (without dapr) //var responseMessage = await _client.GetAsync($"/titlecase?sentence={sentence}"); //var stream = await responseMessage.Content.ReadAsStreamAsync(); //return await JsonSerializer.DeserializeAsync(stream, _options); } } -} \ No newline at end of file +} diff --git a/samples/dapr/service-invocation/SentenceApp/Services/UppercaseServiceClient.cs b/samples/dapr/service-invocation/SentenceApp/Services/UppercaseServiceClient.cs index 4719988f..bac582d4 100644 --- a/samples/dapr/service-invocation/SentenceApp/Services/UppercaseServiceClient.cs +++ b/samples/dapr/service-invocation/SentenceApp/Services/UppercaseServiceClient.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; +using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; using Dapr.Client; -using Dapr.Client.Http; using Shared; namespace SentenceApp.Services @@ -30,16 +26,11 @@ namespace SentenceApp.Services public async Task Convert(string sentence) { // Using Dapr sidecar and service invocation building block - return await _daprClient.InvokeMethodAsync("uppercaseservice", "uppercase", new object(), new HTTPExtension() - { - QueryString = new Dictionary() - { - {"sentence", sentence} - }, - Verb = HTTPVerb.Get - }); + return await _daprClient.InvokeMethodAsync("uppercaseservice", "uppercase", new object(), + HttpInvocationOptions.UsingGet() + .WithQueryParam("sentence", sentence)); - // If you're using Tye alone + // If you're using Tye alone (without dapr) //var responseMessage = await _client.GetAsync($"/uppercase?sentence={sentence}"); //var stream = await responseMessage.Content.ReadAsStreamAsync(); //return await JsonSerializer.DeserializeAsync(stream, _options);