Description
Expected Behavior
Content-Type mismatch in publishEvent call.
When a string event is published, using the
client.publishEvent("pubsubName", "topicName", "This is message #0")
What is seen in the broker for publish using gRPC protocol is:
{"data":"This is message #0","datacontenttype":"application/json","expiration":"2022-09-14T07:34:04Z","id":"87bc9a7b-ab08-4e7a-8583-3f1e0433ab67","pubsubname":"kafka-pubsub","source":"test-batch-pub","specversion":"1.0","topic":"testingtopic","traceid":"00-6b8bfc12d6d2bb6c7e2f80503628f2b8-8a495373d49513aa-01","traceparent":"00-6b8bfc12d6d2bb6c7e2f80503628f2b8-8a495373d49513aa-01","tracestate":"","type":"com.dapr.event.sent"}
Here because the data is not given in the client.publishEvent
call, it is being inferred by the default serializer as application/json
and that is the datacontenttype
field that is set in the cloudEvent in broker.
On subscription, the subscriber correctly reads the value and users see something like
Subscriber got: This is message #0
But when we publish the same data This is message #0
with the publishEvent call with the content type correctly set
PublishEventRequest req = new PublishEventRequest("pubsubName", "topicName", "This is message #0");
req.setContentType("text/plain");
client.publishEvent(req)
The data seen in the broker is such:
{"data":"\"This is message #0\"","datacontenttype":"text/plain","expiration":"2022-09-14T12:32:37Z","id":"e996716d-1d11-46d7-9112-6866cbb633ce","pubsubname":"kafka-pubsub","source":"test-batch-pub","specversion":"1.0","topic":"simpletest","traceid":"00-a58c282daed4035a660abbf14208cac2-283bb02770d94908-01","traceparent":"00-a58c282daed4035a660abbf14208cac2-283bb02770d94908-01","tracestate":"","type":"com.dapr.event.sent"}
and the subscriber actually gets Subscriber got: "This is message #0"
With the right content type given, the serialization is escaping the quotes. But when no content type is given, a wrong content type is assumed.
Actual Behavior
Proper match should be there between datacontenttype field and the actually data field when saved as cloudEvent.
Steps to Reproduce the Problem
send with the overloaded method of publishEvent(pubsub, topic, data)
and publishEvent(publishEventReq)
and set proper metadata for the full request.
Release Note
RELEASE NOTE: