Documentation
¶
Index ¶
Constants ¶
const (
MsgTypeDefault string = "grav.default"
)
MsgTypeDefault and other represent message consts
Variables ¶
var ErrMsgNotWanted = errors.New("message not wanted")
ErrMsgNotWanted is used by WaitOn to determine if the current message is what's being waited on
var (
ErrTransportNotConfigured = errors.New("transport plugin not configured")
)
ErrTransportNotConfigured represent package-level vars
Functions ¶
This section is empty.
Types ¶
type ConnectFunc ¶ added in v0.0.4
type ConnectFunc func() *Pod
ConnectFunc represents a function that returns a pod conntected to Grav
type CreateTransportFunc ¶ added in v0.0.5
type CreateTransportFunc func(*TransportOpts, ConnectFunc) Transport
CreateTransportFunc is a function that returns a transport
type Grav ¶
type Grav struct {
// contains filtered or unexported fields
}
Grav represents a Grav message bus instance
func NewWithTransport ¶ added in v0.0.4
func NewWithTransport(tsptFunc CreateTransportFunc, opts *TransportOpts) *Grav
NewWithTransport creates a new Grav with a transport plugin configured
func (*Grav) ConnectEndpoint ¶ added in v0.0.4
ConnectEndpoint uses the configured transport to connect the bus to an external endpoint
func (*Grav) Serve ¶ added in v0.0.4
Serve directs the configured transport plugin to serve an endpoint that other nodes can connect to Calling Serve will block, so if the Grav endpoint is meant to run in the background, it should be called on a goroutine. Calling Serve is optional if incoming connections are not needed (or if no transport is being used)
type Message ¶ added in v0.0.3
type Message interface { // Unique ID for this message UUID() string // ID of the parent event or request, such as HTTP request ParentID() string // The UUID of the message being responded to, if any ResponseTo() string // Type of message (application-specific) Type() string // Time the message was sent Timestamp() time.Time // Raw data of message Data() []byte // Unmarshal the message's data into a struct UnmarshalData(interface{}) error // Marshal the message itself to encoded bytes (JSON or otherwise) Marshal() ([]byte, error) // Unmarshal encoded Message into object Unmarshal([]byte) error }
Message represents a message
func MsgFromBytes ¶ added in v0.0.3
MsgFromBytes returns a default _message that has been unmarshalled from bytes. Should only be used if the default _message type is being used.
func MsgFromRequest ¶ added in v0.0.3
MsgFromRequest extracts an encoded Message from an HTTP request
func NewMsgResponseTo ¶ added in v0.0.3
NewMsgResponseTo creates a new message in response to a previous message
func NewMsgWithParentID ¶ added in v0.0.3
NewMsgWithParentID returns a new message with the provided parent ID
type MsgChan ¶ added in v0.0.3
type MsgChan chan Message
MsgChan is a channel that accepts a message
type MsgFunc ¶ added in v0.0.3
MsgFunc is a callback function that accepts a message and returns an error
type Pod ¶ added in v0.0.3
Pod is a connection to Grav Pods are bi-directional. Messages can be sent to them from the bus, and they can be used to send messages to the bus. Pods are meant to be extremely lightweight with no persistence they are meant to quickly and immediately route a message between its owner and the Bus. The Bus is responsible for any "smarts". Messages coming from the bus are filtered using the pod's messageFilter, which is configurable by the caller.
func (Pod) FilterType ¶ added in v0.0.3
func (Pod) FilterUUID ¶ added in v0.0.3
FilterUUID likely should not be used in normal cases, it adds a message UUID to the pod's filter.
func (*Pod) On ¶ added in v0.0.3
On sets the function to be called whenever this pod recieves a message from the bus. If nil is passed, the pod will ignore all messages. Calling On multiple times causes the function to be overwritten. To recieve using two different functions, create two pods.
func (*Pod) OnType ¶ added in v0.0.3
OnType sets the function to be called whenever this pod recieves a message and sets the pod's filter to only include certain message types
func (*Pod) WaitOn ¶ added in v0.0.3
WaitOn takes a function to be called whenever this pod recieves a message and blocks until that function returns something other than ErrMsgNotWanted. WaitOn should be used if there is a need to wait for a particular message. When the onFunc returns something other than ErrMsgNotWanted (such as nil or a different error), WaitOn will return and set the onFunc to nil. If an error other than ErrMsgNotWanted is returned from the onFunc, it will be propogated to the caller.
type Transport ¶ added in v0.0.4
type Transport interface { // Serve is a transport-specific function that exposes a connection point Serve() error // ConnectEndpoint indicates to the Transport that a connection to a remote endpoint is needed ConnectEndpoint(string) error }
Transport represents a Grav transport plugin
type TransportOpts ¶ added in v0.0.5
type TransportOpts struct {
// contains filtered or unexported fields
}
TransportOpts is a set of options for transports
func DefaultTransportOpts ¶ added in v0.0.5
func DefaultTransportOpts() *TransportOpts
DefaultTransportOpts returns the default Grav Transport options