Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Fix dapr recipe documentation and update sample to use latest .Net Da…
Browse files Browse the repository at this point in the history
…pr sdk (#878)
  • Loading branch information
dasiths authored Jan 6, 2021
1 parent 45bf552 commit 1342e86
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 47 deletions.
17 changes: 11 additions & 6 deletions docs/recipes/dapr.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@ 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`)
- An order fulfillment service (`orders`)

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
Expand Down Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="0.11.0-preview02" />
<PackageReference Include="Dapr.Client" Version="0.11.0-preview02" />
<PackageReference Include="Dapr.AspNetCore" Version="1.0.0-rc02" />
<PackageReference Include="Dapr.Client" Version="1.0.0-rc02" />
<PackageReference Include="Microsoft.Tye.Extensions.Configuration" Version="0.5.0-alpha.20555.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,18 +26,14 @@ public LowercaseServiceClient(HttpClient client, DaprClient daprClient)
public async Task<ConvertedResult> Convert(string sentence)
{
// Using Dapr sidecar and service invocation building block
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("lowercaseservice", "lowercase", new object(), new HTTPExtension()
{
QueryString = new Dictionary<string, string>()
{
{"sentence", sentence}
},
Verb = HTTPVerb.Get
});
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("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<ConvertedResult>(stream, _options);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,19 +26,14 @@ public TitlecaseServiceClient(HttpClient client, DaprClient daprClient)
public async Task<ConvertedResult> Convert(string sentence)
{
// Using Dapr sidecar and service invocation building block
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("titlecaseservice", "titlecase", new object(), new HTTPExtension()
{
QueryString = new Dictionary<string, string>()
{
{"sentence", sentence}
},
Verb = HTTPVerb.Get
});
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("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<ConvertedResult>(stream, _options);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -30,16 +26,11 @@ public UppercaseServiceClient(HttpClient client, DaprClient daprClient)
public async Task<ConvertedResult> Convert(string sentence)
{
// Using Dapr sidecar and service invocation building block
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("uppercaseservice", "uppercase", new object(), new HTTPExtension()
{
QueryString = new Dictionary<string, string>()
{
{"sentence", sentence}
},
Verb = HTTPVerb.Get
});
return await _daprClient.InvokeMethodAsync<object, ConvertedResult>("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<ConvertedResult>(stream, _options);
Expand Down

0 comments on commit 1342e86

Please sign in to comment.