Skip to content

Send to NServiceBus

Note

NServiceBus licensing. NServiceBus is dual-licensed: the Reciprocal Public License 1.5, or Particular Software's commercial agreement (particular.net/LicenseAgreement). This format was captured from NServiceBus 10.2.9, and only the module's own .NET test programs use it. The Go module itself does not depend on NServiceBus.

Choose the format as the writer

nservicebus.NServiceBus() is an envelope.Format. Give it to the adapter as the one format every event is published with. With go/messaging-rabbitmq, that is Settings.Format:

rabbitmq.New(rabbitmq.Settings{
    URL: url, Exchange: "events",
    Format: nservicebus.NServiceBus(),
    Reads:  []envelope.Format{cloudevents.Binary(cloudevents.HTTP), cloudevents.Structured(), nservicebus.NServiceBus()},
})

Reads is the chain a received message is read with. See Read more than one format. That adapter writes NServiceBus's headers into the message's headers table and Wire.ContentType on its content type. The queue and routing an NServiceBus endpoint expects are not covered by this module.

Shape the event for a .NET endpoint

Attribute Set it to
ID Any string. NServiceBus's IDs are strings, so a UUID is not required.
Type The message type's full name, Shop.Messages.PlaceOrder, or its assembly-qualified name.
Source The sending endpoint's name, such as Shop.Sales. It is required.
DataContentType The media type of the payload, which NServiceBus uses to pick a deserializer.
Data The payload in that format. Any bytes: the format does not constrain them.

Set both ID and Source: an event without either is refused by validation before it is written.

Time is written to the microsecond. Finer is truncated, never refused.

Do not put a semicolon in the type

NServiceBus.EnclosedMessageTypes separates the types a message implements with ;, and the format reads only the text before the first one as the type. In v0.1.0, the released version, Encode does not refuse a type containing ;, so it reads back shortened. From the next release Encode refuses it with envelope.ErrUnrepresentable (envelope-nservicebus!4).

With a trace

Set the traceparent extension; it is written as a header of that name. See Carry headers and foreign fields.