From c9e388c05460f3ad034a969d6273c571fb98c2e0 Mon Sep 17 00:00:00 2001 From: Paul Yuknewicz Date: Mon, 31 Jan 2022 10:13:26 -0800 Subject: [PATCH] Adding Dotnet readme, and fixed bugs on .NET 6 routes Signed-off-by: Paul Yuknewicz --- pub_sub/csharp/README.md | 99 +++++++++++++++++++ pub_sub/csharp/order-processor/Program.cs | 4 +- .../order-processor/order-processor.csproj | 7 +- 3 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 pub_sub/csharp/README.md diff --git a/pub_sub/csharp/README.md b/pub_sub/csharp/README.md new file mode 100644 index 00000000..20098634 --- /dev/null +++ b/pub_sub/csharp/README.md @@ -0,0 +1,99 @@ +# Dapr pub/sub + +In this quickstart, you'll create a publisher microservice and a subscriber microservice to demonstrate how Dapr enables a publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscribers will listen for messages of specific topics. See [Why Pub-Sub](#why-pub-sub) to understand when this pattern might be a good choice for your software architecture. + +Visit [this](https://docs.dapr.io/developing-applications/building-blocks/pubsub/) link for more information about Dapr and Pub-Sub. + +This quickstart includes one publisher: + +- Dotnet client message generator `checkout` + +And one subscriber: + +- Dotnet subscriber `order-processor` + +### Run Dotnet message publisher with Dapr + +1. Open a new terminal window and navigate to `checkout` directory: + +```bash +cd checkout +``` + +2. Install dependencies: + + + +```bash +dotnet restore +dotnet build +``` + +3. Run the Dotnet publisher app with Dapr: + + + +```bash +dapr run --app-id checkout --components-path ../../components/ -- dotnet run +``` + + +### Run Dotnet message subscriber with Dapr + +1. Open a new terminal window and navigate to `checkout` directory: + +```bash +cd order-processor +``` + +2. Install dependencies: + + + +```bash +dotnet restore +dotnet build +``` + +3. Run the Dotnet subscriber app with Dapr: + + + + +```bash +dapr run --app-id order-processor --components-path ../../components/ --app-port 5001 -- dotnet run +``` + + \ No newline at end of file diff --git a/pub_sub/csharp/order-processor/Program.cs b/pub_sub/csharp/order-processor/Program.cs index 8277f1c4..a143916e 100644 --- a/pub_sub/csharp/order-processor/Program.cs +++ b/pub_sub/csharp/order-processor/Program.cs @@ -20,9 +20,9 @@ app.MapGet("/dapr/subscribe", () => { return subscriptions; }); -app.MapPost("/orders", async (Order order) => { +app.MapPost("/orders", (Order order) => { Console.WriteLine("Subscriber received : " + order.ToString()); - return new HttpResponseMessage(HttpStatusCode.OK); + return Results.Ok(order.ToString()); }); // [Topic("order_pub_sub", "orders")] diff --git a/pub_sub/csharp/order-processor/order-processor.csproj b/pub_sub/csharp/order-processor/order-processor.csproj index dec6078e..13a8c2a6 100644 --- a/pub_sub/csharp/order-processor/order-processor.csproj +++ b/pub_sub/csharp/order-processor/order-processor.csproj @@ -2,12 +2,13 @@ net6.0 + disable + enable + Linux - - - +