Closed yanmxa closed 5 months ago
When setting the event transfer with structured mode by MQTT protocol. The content-type might be set more than one times, see the MQTT payload below.
content-type
... ctx = cloudevents.WithEncodingStructured(ctx) if result := c.Send( cecontext.WithTopic(ctx, "test-topic"), e, ); cloudevents.IsUndelivered(result) { log.Printf("failed to send: %v", result) } else { log.Printf("sent: %d, accepted: %t", i, cloudevents.IsACK(result)) }
{ "PacketID": 0, "QoS": 0, "Retain": false, "Topic": "test-topic", "Properties": { "CorrelationData": null, "ContentType": "", "ResponseTopic": "", "PayloadFormat": null, "MessageExpiry": null, "SubscriptionIdentifier": null, "TopicAlias": null, "User": [ { "Key": "Content-Type", "Value": "application/cloudevents+json" }, { "Key": "Content-Type", "Value": "application/cloudevents+json" }, { "Key": "Content-Type", "Value": "application/cloudevents+json" }, { "Key": "Content-Type", "Value": "application/cloudevents+json" } ] }, "Payload": "eyJzcGVjdmVyc2lvbiI6IjEuMCIsImlkIjoiNTVkM2NhYTktOTA2ZC00MDE0LWI3YTYtZDUyOTA3NjAxZTE2Iiwic291cmNlIjoiaHR0cHM6Ly9naXRodWIuY29tL2Nsb3VkZXZlbnRzL3Nkay1nby9zYW1wbGVzL21xdHQvc2VuZGVyIiwidHlwZSI6ImNvbS5jbG91ZGV2ZW50cy5zYW1wbGUuc2VudCIsImRhdGFjb250ZW50dHlwZSI6ImFwcGxpY2F0aW9uL2pzb24iLCJ0aW1lIjoiMjAyNC0wNS0yM1QwMjowNTozMS4zMzU5NzNaIiwiZGF0YSI6eyJpZCI6MywibWVzc2FnZSI6IkhlbGxvLCBXb3JsZCEifSwiZXZlbnRrZXkiOiJldmVudHZhbHVlIn0=" }
So instead of setting the content-type in the userProperties list, we can leverage the ContentType in the MQTT properties directly.
userProperties
ContentType
When setting the event transfer with structured mode by MQTT protocol. The
content-type
might be set more than one times, see the MQTT payload below.So instead of setting the
content-type
in theuserProperties
list, we can leverage theContentType
in the MQTT properties directly.