dapr / dotnet-sdk

Dapr SDK for .NET
Apache License 2.0
1.11k stars 334 forks source link

Custom CloudEvent serialization problem - Data property #944

Open mzj opened 2 years ago

mzj commented 2 years ago

Intro

I've stumbled on a problem while publishing events with a custom CloudEvent wrapper. I'm trying to use custom CloudEvent so that I can specify the type property and use it for routing functionality inside subscribers.

Related to Allow publishing cloud events directly #868 The project is using docker-compose to set up the whole infrastructure (pub/sub services, dapr sidecars, Kafka, etc) for testing. Demo project based on Dapr and Dapr.AspNetCore ver. 1.8, and .Net 5 (Web Api)

Expected Behavior

Published cloud event JSON schema should look like events published without custom cloud events.

Actual Behavior

Dapr sidecar log shows the following warning/error:

level=warning msg="retriable error returned from app while processing pub/sub event <nil>, topic: RoutingIntegrationEvent, body: {\"type\":\"https://tools.ietf.org/html/rfc7231#section-6.5.13\",\"title\":\"Unsupported Media Type\",\"status\":415,\"traceId\":\"00-9c97aa770091eb243c1f904fbd88c27f-cfe48e0d27c8fc42-01\"}. status code returned: 415" app_id=subscriber instance=b398cfe88dc9 scope=dapr.runtime type=log ver=1.8.0

After comparing published events with and without a custom CE wrapper I've noticed that the "data" property is different between those two types of events. Specifically, pure event serializes cloud event with "data" property, while custom CE serializes it into uppercase "Data" property.

Steps to Reproduce the Problem

  1. Clone the repository with the fixed and runnable project (under docker-compose). https://github.com/mzj/PubSubRouting
  2. Remove the above-mentioned attribute to reproduce the problem.
  3. Run the solution (tested in VS2022)

Fix

Adding [JsonPropertyName("data")] attribute to CloudEvent.Data property, inside Dapr.Client project.

Release Note

FIX Bug in runtime.

LotteVoorhorst commented 4 months ago

This is still a problem today. The event cannot be used because of the parsing mismatch. Any updates on this soon?