payload

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments

type Arguments map[string]interface{}

Arguments is a set of key-value pairs containing arguments specific to a Step

type Document

type Document struct {
	ContentType string `json:"content_type"`
	Data        string `json:"data"`

	Encoding Encoding `json:"encoding,omitempty"`
	// contains filtered or unexported fields
}

Document is a payload item containing the payload data, content type, and optional encoding.

func InitDocument

func InitDocument(ct string, enc Encoding) Document

InitDocument starts a blank document with the content type and desired encoding.

func NewDocument

func NewDocument(data string, ct string, enc Encoding) Document

NewDocument creates a new document of string data with content type, and encoding.

func (Document) Close

func (d Document) Close() error

Close does nothing. It exists to adhere to the WriteCloser interface.

func (*Document) Read

func (d *Document) Read(p []byte) (n int, err error)

Read returns a slice of the Document data verbatim. It does not apply the appropriate; use the Reader().Read() method for this purpose.

func (*Document) Reader

func (d *Document) Reader() (r io.Reader)

Reader returns an io.Reader for the document data with the appropriate encoding applied

func (*Document) Write

func (d *Document) Write(data []byte) (n int, err error)

Write appends the provided bytes to the Document data verbatim. It does not apply the appropriate; use the WriteCloser method for this purpose.

func (*Document) WriteCloser

func (d *Document) WriteCloser() (w io.WriteCloser)

WriteCloser returns a stream writer that applies the appropriate encoding. When finished writing, the caller must Close the returned encoder to flush any partially written data.

type Documents

type Documents map[string]Document

Documents contains a set of Documents by name

type Encoding

type Encoding string

Encoding is a supported Document encoding type

const (
	// NoEncoding is the default document data encoding, which should be json
	// serializable.
	NoEncoding Encoding = ""
	// Base64Encoding is the default encoding for binary documents, so it can be
	// json compatible
	Base64Encoding Encoding = "base64"
)

type ErrorHandling

type ErrorHandling struct {
	MaxRetries int `json:"max_retries"`
	Attempt    int `json:"attempt,omitempty"`
	Rewind     int `json:"rewind,omitempty"`
}

ErrorHandling declares how failed steps are to be handled. Currently focusses on retry limits, and (partially) rewinding the route position.

type Message

type Message struct {
	Routing   `json:"routing"`
	TraceID   string `json:"trace_id"`
	MetaData  `json:"metadata,omitempty"`
	Documents `json:"documents,omitempty"`
}

Message is a simple example message

func MessageFromByteSlice

func MessageFromByteSlice(b []byte) (*Message, error)

MessageFromByteSlice unmarshals a JSON byte slice into a Message.

func NewMessage

func NewMessage(route Routing, meta MetaData, docs Documents) Message

NewMessage creates a new Message with a unique TraceID, and attaches the routing slip, metadatam and documents.

func NewMessageForRoute

func NewMessageForRoute(route string, meta MetaData, docs Documents) Message

NewMessageForRoute creates a new Message with a unique TraceID to send to the post-office for the route by name.

func (Message) Advance

func (msg Message) Advance(pl *Documents, md *MetaData) (*Message, error)

Advance creates a new Message based on the current message, but with updated documents and advanced routing position. Returns nil if there is no next step.

func (Message) CurrentStep

func (msg Message) CurrentStep() (*Step, error)

CurrentStep return the Step at the current position in the routing slip.

func (Message) Retry

func (msg Message) Retry(e error) (*Message, error)

Retry creates a new Message based on the current message, but with updated attempt count, and possibly a partially reset Position. Returns nil if the number of retries has been exhausted.

type MetaData

type MetaData map[string]interface{}

MetaData is a set of key-value pairs containing general information about a Message

type Routing

type Routing struct {
	Name     string `json:"name"`
	Position int    `json:"position"`
	Slip     []Step `json:"slip"`
}

Routing contains the routing name, slip, and current step number.

type Step

type Step struct {
	Queue         string `json:"queue"`
	Arguments     `json:"arguments,omitempty"`
	ErrorHandling `json:"on_error,omitempty"`
	Log           []string `json:"log,omitempty"`
}

Step is a single processing step in a routing slip

Jump to

Keyboard shortcuts

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