nservicebus

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 Imported by: 0

README

envelope-nservicebus

NServiceBus's message headers as a go/envelope format, so a Go service on the estate's bus exchanges messages with .NET services that use NServiceBus.

Go Reference pipeline

Part of the envelope family. It is documented with its core, at envelope.go.phpboyscout.uk.

go get gitlab.com/phpboyscout/go/envelope-nservicebus
f := nservicebus.NServiceBus() // an envelope.Format

Give it to a go/messaging 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 event travels in NServiceBus's own headers and the payload as the body, unconstrained. TimeSent keeps microseconds. What an NServiceBus message carries that the event has no place for (its conversation and correlation IDs, intent, machine and the rest) arrives as envelope.Foreign. The full rules are on NServiceBus.

The decisions are go/messaging's spec 0014, D2, D9 and D10.

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

View Source
const (
	HeaderMessageID            = "NServiceBus.MessageId"
	HeaderEnclosedMessageTypes = "NServiceBus.EnclosedMessageTypes"
	HeaderOriginatingEndpoint  = "NServiceBus.OriginatingEndpoint"
	HeaderContentType          = "NServiceBus.ContentType"
	HeaderTimeSent             = "NServiceBus.TimeSent"
)

The NServiceBus headers that carry the event.

View Source
const (
	HeaderSubject    = "ce-subject"
	HeaderDataSchema = "ce-dataschema"
)

The headers carrying the attributes NServiceBus has no header for.

View Source
const Precision = time.Microsecond

Precision is TimeSent's: a microsecond. Encode truncates to it (go/messaging spec 0014 D2).

Variables

View Source
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

func NServiceBus() envelope.Format

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL