[Pub/sub subscriptions] Fix C# example (#2545)

* fix csharp example per hal

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* update per Mark

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

* add second example

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>

Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
Hannah Hunter 2022-06-24 14:37:55 -05:00 committed by GitHub
parent f88c853c4e
commit b00ce0371e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 4 deletions

View File

@ -191,15 +191,25 @@ The programmatic approach returns the `routes` JSON structure within the code, u
{{% codetab %}}
```csharp
[Topic("pubsub", "checkout", event.type ==\"order\"")]
[HttpPost("orders")]
public async Task<ActionResult<Stock>> HandleCheckout(Checkout checkout, [FromServices] DaprClient daprClient)
[Topic("pubsub", "orders")]
[HttpPost("/checkout")]
public async Task<ActionResult<Order>>Checkout(Order order, [FromServices] DaprClient daprClient)
{
// Logic
return stock;
return order;
}
```
or
```csharp
// Dapr subscription in [Topic] routes orders topic to this route
app.MapPost("/checkout", [Topic("pubsub", "orders")] (Order order) => {
Console.WriteLine("Subscriber received : " + order);
return Results.Ok(order);
});
```
{{% /codetab %}}
{{% codetab %}}