From bd9eb23110f43db5fa7f4304b0e4e945dd67f1dd Mon Sep 17 00:00:00 2001 From: Fernando Rocha Date: Thu, 30 Jan 2025 18:13:44 -0800 Subject: [PATCH] including .NET publisher example Signed-off-by: Fernando Rocha --- .../building-blocks/pubsub/pubsub-raw.md | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-raw.md b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-raw.md index 844750650..6431b97cc 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-raw.md +++ b/daprdocs/content/en/developing-applications/building-blocks/pubsub/pubsub-raw.md @@ -20,7 +20,7 @@ Not using CloudEvents disables support for tracing, event deduplication per mess To disable CloudEvent wrapping, set the `rawPayload` metadata to `true` as part of the publishing request. This allows subscribers to receive these messages without having to parse the CloudEvent schema. -{{< tabs curl "Python SDK" "PHP SDK">}} +{{< tabs curl ".NET" "Python SDK" "PHP SDK">}} {{% codetab %}} ```bash @@ -28,6 +28,46 @@ curl -X "POST" http://localhost:3500/v1.0/publish/pubsub/TOPIC_A?metadata.rawPay ``` {{% /codetab %}} +{{% codetab %}} + +```csharp +using Dapr.Client; +using Shared; + +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddControllers().AddDapr(); + +var app = builder.Build(); + +app.MapGet("/", () => "Publisher API"); + +app.MapPost("/publish", async (DaprClient daprClient) => +{ + var message = new Message( + Guid.NewGuid().ToString(), + $"Hello at {DateTime.UtcNow}", + DateTime.UtcNow + ); + + await daprClient.PublishEventAsync( + "pubsub", // pubsub name + "messages", // topic name + message, // message data + new Dictionary + { + { "rawPayload", "true" }, + { "content-type", "application/json" } + } + ); + + return Results.Ok(message); +}); + +app.Run(); +``` + +{{% /codetab %}} + {{% codetab %}} ```python from dapr.clients import DaprClient