Documentation
¶
Overview ¶
Package nservicebus is NServiceBus's message headers as a go/envelope format, so a Go service on the estate's bus can exchange messages with .NET services that use NServiceBus.
NServiceBus returns the envelope.Format. Give it to an adapter as the writer to send to NServiceBus endpoints, or add it to the reader chain to read what NServiceBus endpoints send; envelope.Read tells it apart from CloudEvents by its NServiceBus.MessageId header.
The rules it holds an event to, and where each attribute travels, are on NServiceBus. The decisions are go/messaging spec 0014's D2, D9 and D10.
Index ¶
Examples ¶
Constants ¶
const ( HeaderMessageID = "NServiceBus.MessageId" HeaderEnclosedMessageTypes = "NServiceBus.EnclosedMessageTypes" HeaderOriginatingEndpoint = "NServiceBus.OriginatingEndpoint" HeaderContentType = "NServiceBus.ContentType" HeaderTimeSent = "NServiceBus.TimeSent" )
The NServiceBus headers that carry the event.
const ( HeaderSubject = "ce-subject" HeaderDataSchema = "ce-dataschema" )
The headers carrying the attributes NServiceBus has no header for.
const Precision = time.Microsecond
Precision is TimeSent's: a microsecond. Encode truncates to it (go/messaging spec 0014 D2).
Variables ¶
var ErrAmbiguousHeader = errors.NewSentinel("nservicebus.ambiguous_header",
"nservicebus: a header was supplied under two spellings with different values")
ErrAmbiguousHeader is returned when one of NServiceBus's headers arrives under two spellings with different values. Header maps differ in whether they fold case, so neither can be taken as the one the producer meant. Every other refusal is a go/envelope sentinel, so it is counted by the same code whichever format carried the event.
Functions ¶
func NServiceBus ¶
NServiceBus is NServiceBus's message: the event in its headers, the payload as the body.
The ID, type, source, datacontenttype and time are NServiceBus's own headers (HeaderMessageID and the rest). The type is EnclosedMessageTypes, so a .NET handler for Shop.Messages.PlaceOrder wants the type "Shop.Messages.PlaceOrder", its full name, or its assembly-qualified name; the source is OriginatingEndpoint, an endpoint's name. Any ID is carried, since NServiceBus's are strings. Subject and dataschema travel as HeaderSubject and HeaderDataSchema, and each extension as a header of its own name. TimeSent is truncated to Precision. The payload is not constrained: NServiceBus picks its deserializer by the content type. A type containing ';', which separates EnclosedMessageTypes' entries, is refused as envelope.ErrUnrepresentable.
It recognises a message by its NServiceBus.MessageId header. On read, a header whose name is an extension name (lower-case letters and digits, and not an attribute's) is an extension, because headers are where this format writes them, so a broker's or a producer's header such as priority or tenant arrives as one too. That is how traceparent is promoted, and why a case variant such as Traceparent is not. Every other header is envelope.Foreign, and so are EnclosedMessageTypes' entries after the first, kept as the header's whole value. NServiceBus's headers are matched in any case, since a header map may fold it, and two spellings of one with different values are ErrAmbiguousHeader. A transport content type that disagrees with NServiceBus.ContentType is a conflict: the envelope's is the event's, and the transport's is foreign, as content-type.
Example ¶
ExampleNServiceBus writes an event for a .NET handler of Shop.Messages.PlaceOrder, and reads it back the way a reader chain would.
package main
import (
"fmt"
"gitlab.com/phpboyscout/go/envelope"
nservicebus "gitlab.com/phpboyscout/go/envelope-nservicebus"
)
func main() {
f := nservicebus.NServiceBus()
w, err := f.Encode(envelope.Event{
ID: "7f2c1a9e-0000-4000-8000-000000000001",
Source: "Shop.Sales",
Type: "Shop.Messages.PlaceOrder",
DataContentType: "application/json",
Data: []byte(`{"Order":"4172"}`),
})
if err != nil {
fmt.Println("encode:", err)
return
}
fmt.Println(w.Headers["NServiceBus.EnclosedMessageTypes"][0])
e, _, format, err := envelope.Read(w, f)
if err != nil {
fmt.Println("read:", err)
return
}
fmt.Println(format, e.Source, string(e.Data))
}
Output: Shop.Messages.PlaceOrder nservicebus Shop.Sales {"Order":"4172"}
Types ¶
This section is empty.