Read from MassTransit¶
Warning
MassTransit 9 is commercially licensed. MassTransit 9 and later is under the MassTransit Commercial Software License Agreement (massient.com/license), a paid subscription with no exemption for testing. This format was captured from MassTransit 8, which is Apache-2.0, and the module's own .NET test programs stay on 8.x (envelope-masstransit#1). The Go module itself does not depend on MassTransit.
Add it to the chain¶
readers := []envelope.Format{
cloudevents.Binary(cloudevents.HTTP),
cloudevents.Structured(),
masstransit.MassTransit(),
}
e, foreign, format, err := envelope.Read(w, readers...)
Read tells MassTransit apart from the others by the content type: it claims a message whose content
type, parsed as a media type, is application/vnd.masstransit+json. Parameters such as
; charset=utf-8 are ignored. The content type is read from Wire.ContentType, or, on a transport
without a native one, from a content-type header in any case.
What you get¶
For a message MassTransit sent with nothing set, testdata/plain.txt:
e.IDis themessageIdande.Sourceis thesourceAddress, which on MassTransit is where the producing bus is.e.Typeis the firstmessageTypewithouturn:message:.e.TimeissentTime.e.Datais themessageobject exactly as it arrived, whitespace included.e.DataContentTypeis empty. MassTransit does not write one.foreign.HeadersholdsconversationId,destinationAddressandhost.
Reply in the format Read returned, so a MassTransit caller gets a MassTransit answer.
Decode the payload¶
e.Data is JSON. Decode it into a value you provide; the format never infers a Go type from the
wire:
MassTransit's serializer writes property names in camel case, as the fixtures show ("order",
"lines"), so a struct needs json tags for them.
A message with no data¶
A message whose message is {} reads with {} as its data. An event written without data reads
back the same way, so len(e.Data) == 0 is not a test for "no payload" on this format.
A message it cannot read¶
A messageId that is not a UUID, a body that is not a JSON object and a member that appears twice are
all refused, and the partial event is returned with the error. See
Handle what MassTransit refuses.