Class CloudEventTransportMessageExtensions
Attaches a CloudEvent to an outbound message so the transport publishes it as a CloudEvent.
public static class CloudEventTransportMessageExtensions
- Inheritance
-
CloudEventTransportMessageExtensions
- Inherited Members
Methods
WithCloudEvent(TransportMessage, CloudEvent)
Marks the message to be published as a CloudEvent.
public static TransportMessage WithCloudEvent(this TransportMessage message, CloudEvent cloudEvent)
Parameters
messageTransportMessageThe message to publish.
cloudEventCloudEventThe event to publish it as.
Returns
- TransportMessage
The same message, so the call can be chained onto construction.
Remarks
This is the only supported way to ask for CloudEvents encoding on the send path, and it exists because the alternative did not work. The encoder reads a marker from Properties; without a typed method the caller had to know the marker's key, which lives on an internal type and so could only be supplied as a hand-written string copied out of framework source. A capability reachable only by a literal nobody can discover is not opt-in, it is unreachable — so the door is a method on the type the caller already holds, where it appears in completion beside everything else they can do to a message.
Sending is unchanged for any message this is not called on. The encoding decorator rewrites only messages carrying the marker, so ordinary traffic reaches the wire byte-identical whether or not a transport is wrapped.
The event is encoded in CloudEvents structured mode: the whole event becomes a JSON document in
the body under the application/cloudevents+json content type. That content type is the
only thing identifying the message as a CloudEvent, so encoding is enabled per transport rather
than everywhere — a transport whose send path cannot carry a media type end to end would emit a
body no conformant receiver could recognise. Transports shipping their own protocol-binding encoder
continue to use it.