Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosedMessageWriter = errors.New("msg: MessageWriter closed")
ErrClosedMessageWriter is the error used for write or close operations on a closed MessageWriter.
var ErrServerClosed = errors.New("msg: server closed")
ErrServerClosed represents a completed Shutdown
Functions ¶
Types ¶
type Attributes ¶
Attributes represent the key-value metadata for a Message.
func (Attributes) Get ¶
func (a Attributes) Get(key string) string
Get returns the first value associated with the given key. It is case insensitive; CanonicalMIME is used to cannonicalize the provided key. If there are no values associated with the key, Get returns "". To access multiple values of a key, or to use non-canonical keys, access the map directly.
func (Attributes) Set ¶
func (a Attributes) Set(key, value string)
Set sets the header entries associated with key the single element element value. It replaces any existing values associated with key.
Note: MIMEHeader automatically capitalizes the first letter of the key.
type Message ¶
type Message struct { Attributes Attributes Body io.Reader }
A Message represents a discrete message in a messaging system.
type MessageWriter ¶
type MessageWriter interface { io.Writer // Close should be called to signify the completion of a Write. Attributes // that represent a transform applied to a message should also be written // at this time. // // Close should forward a message to another MessageWriter or persist // to the messaging system. // // Once Close has been called, all subsequent Write and Close calls will result // in an ErrClosedMessageWriter error. io.Closer Attributes() *Attributes }
A MessageWriter interface is used to write a message to an underlying data stream.
type Receiver ¶
A Receiver processes a Message.
Receive should process the message and then return. Returning signals that the message has been processed. It is not valid to read from the Message.Body after or concurrently with the completion of the Receive call.
If Receive returns an error, the server (the caller of Receive) assumes the message has not been processed and, depending on the underlying pub/sub system, the message should be put back on the message queue.
type ReceiverFunc ¶
The ReceiverFunc is an adapter to allow the use of ordinary functions as a Receiver. ReceiverFunc(f) is a Receiver that calls f.
type SafeReceiver ¶
type SafeReceiver struct {
// contains filtered or unexported fields
}
SafeReceiver is a wrapper for any Receiver that will recover from any panic and instead return an error. This can be used to prevent a single message from tanking the entire process and thereby disrupting other workers.
func NewSafeReceiver ¶
func NewSafeReceiver(r Receiver) *SafeReceiver
NewSafeReceiver returns a new SafeReceiver wrapping the provided Receiver.
type Server ¶
type Server interface { // Serve is a blocking function that gets data from an input stream, // creates a message, and calls Receive() on the provided receiver // with the Message and a Context derived from context.Background(). // For example: // // parentctx = context.WithCancel(context.Background()) // err := r.Receive(parentctx, m) // // Serve will return ErrServerClosed after Shutdown completes. Additional // error types should be considered to represent error conditions unique // to the implementation of a specific technology. // // Serve() should continue to listen until Shutdown is called on // the Server. Serve(context.Context, Receiver) error // Shutdown gracefully shuts down the Server by letting any messages in // flight finish processing. If the provided context cancels before // shutdown is complete, the Context's error is returned. Shutdown(context.Context) error }
A Server serves messages to a receiver.
type Topic ¶
type Topic interface { // NewWriter returns a new MessageWriter NewWriter(context.Context) MessageWriter }
Topic is a generic interface where messages are sent in a messaging system.
Multiple goroutines may invoke method on a Topic simultaneously.
type TopicFunc ¶
type TopicFunc func(context.Context) MessageWriter
The TopicFunc is an adapter to allow the use of ordinary functions as a Topic. TopicFunc(f) is a Topic that calls f.