Why the MassTransit format refuses what it does¶
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.
A format "decides nothing the bus relies on, with two stated exceptions". The MassTransit format uses the first: it refuses to write what its envelope cannot carry. This page is why those two things, and why not others.
An ID that is not a UUID¶
MassTransit's messageId is a .NET Guid. The event's ID is a string, and the bus's identity is the
source and the ID together. There are four things a format could do with an ID that is not a Guid:
refuse it, mint a new one, blank it or derive one. The design record says prior art does all four, and
only refusal keeps deduplication honest.
So Encode refuses with ErrUnrepresentable, naming
the ID. The same holds on read: a messageId that is not a Guid is refused, never re-minted or
blanked.
The check is on shape, not on parsing: eight, four, four, four and twelve hex digits with dashes, in either case. A Guid in braces is refused.
A payload that is not JSON¶
MassTransit's message member is a JSON value. A protobuf payload, or text that is not JSON, has no
place in it. Writing it as a string would hand a .NET consumer a string where it expects an object.
The refusal is on the publish path, so the caller sees it from Publish, never as a message lost
after it is sent. The alternative, a format declaring its constraints as a capability the conformance
suite reads, had no precedent in the prior art the design looked at. The check is both ways: the data
must be valid JSON, and the DataContentType must say JSON or be empty, so JSON labelled text/plain
is refused too.
What it carries instead of refusing¶
Two cases MassTransit reads differently are carried, not refused. They were measured against MassTransit 8.5.10's own deserializer.
- An event without data is written with
{}as its message. MassTransit refuses an envelope whose message is null or absent, and refusing the event instead would stop the bus's failure reply, which has no data, from answering a MassTransit-format request. The cost is that it reads back as{}. - A relative source is written as it is.
sourceAddressis aUriin .NET, so/ordersarrives there asfile:///orders. Go reads it back exactly.
Time is the second stated exception: a format may lower precision to its own and nothing else.
time.Now() carries nanoseconds, so refusing finer times would refuse nearly every real event.
Why a duplicate member is refused on read¶
encoding/json keeps the last of two members with one name. A reader that kept the first would then
see a different event, and so would one in another language. A body with two messageId members has
no single meaning, so it is refused as ErrInvalidEnvelope and the first value is kept in the partial
event for the log.
The open question¶
The design record lists, as not yet specified, whether refusing at publish is enough. It was chosen before any interop format existed, and the rules may want reshaping now that this one has run against real producers.