Skip to content

What the MassTransit format refuses

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.

Recognition

Recognises parses the content type as a media type and claims the message when it is exactly application/vnd.masstransit+json. The content type is Wire.ContentType, or, when that is empty, a content-type header in any case. These cases are checked in the module's tests:

Content type Claimed
application/vnd.masstransit+json yes
application/vnd.masstransit+json; charset=utf-8 yes
Content-Type header of the same, with no Wire.ContentType yes
application/vnd.masstransit+xml no
application/json no
application/cloudevents+json no
a ce-specversion header only no
nothing no

A message that is also claimed by another format, such as one carrying a ce-specversion header, is ErrAmbiguous under envelope.Read.

On Encode

Encode fills in an empty SpecVersion, runs Validate, and then:

Rule Error
ID is not a UUID shape ErrUnrepresentable, id "...": messageId is a Guid
Data is present and DataContentType is not empty, application/json, text/json or a +json type ErrUnrepresentable, data with datacontenttype "...": message is a JSON value
Data is present and is not valid JSON the same

A DataContentType that does not parse as a media type is not JSON. The tests refuse a UUID in braces, application/protobuf, text/plain with text, bytes that are not JSON, and JSON labelled text/plain, and accept an upper-case UUID, text/json, and application/problem+json.

An event with no source is refused by validation as ErrMissingAttribute, not as unrepresentable.

On Decode

The first problem found is returned, with the partial event and Foreign. In order:

Error Cause
ErrInvalidEnvelope The body is not a JSON object, has data after it, a member twice, or an unreadable member. These come before any member-level problem
ErrInvalidEnvelope messageId or sourceAddress is not a string, or messageType is not an array of strings
ErrInvalidEnvelope or ErrInvalidTime sentTime is not a string, or is a string that is not RFC 3339
ErrInvalidEnvelope headers is not an object
ErrUnrepresentable messageId is present and not a UUID shape
a Validate sentinel Anything else, such as no messageId or no sourceAddress or messageType (ErrMissingAttribute)

Not refused

Case What happens
A sourceAddress that is not an absolute URI Carried as the source
A messageType with no urn:message: prefix Used whole as the type
An empty messageType array The type is empty, so validation refuses it as missing
A body with extra members They are foreign
A transport header Foreign, a promoted traceparent, or a conflict. Never an error