Documentation ¶
Overview ¶
Package broker contains the broker implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
The Broker type represents a node in the cluster, it contains the list of all other members as well as a map of connected client channels.
func New ¶
func New(ml Memberlist, cl *http.Client) *Broker
New creates a new instance of the Broker type using the given member list and node.
func (*Broker) Close ¶
func (b *Broker) Close()
Close blocks the goroutine until all asynchronous operations of the broker have stopped.
func (*Broker) NewClient ¶
NewClient creates a new client for a given channel. If the channel does not exist, it is created.
func (*Broker) Publish ¶
Publish writes a given message to a client. If no client identifier is specified, the message is written to the entire channel. If running in a cluster, the event is forwarded asynchronously via HTTP to the next node whose id does not exist in the message's BeenTo field.
func (*Broker) RemoveClient ¶
RemoveClient removes a client from a channel. If the channel has no connected clients, it is also removed.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
The Channel type represents a channel within the broker. Each channel has a unique identifier and can have one or more clients. When events are published to a channel, a client is chosen at random
func NewChannel ¶
NewChannel creates a new instance of the Channel type using the given identifier
func (*Channel) NumClients ¶
NumClients returns the total number of clients for a channel.
func (*Channel) RemoveClient ¶
RemoveClient removes a client from the channel
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client type represents a single client connected to the broker
type Memberlist ¶
type Memberlist interface { NumMembers() int LocalNode() *memberlist.Node Members() []*memberlist.Node }
The Memberlist type represents the gossip implementation used by the broker for service discovery.
type Message ¶
type Message struct { // The event ID to set the EventSource object's last event ID value. ID string `json:"id"` // A string identifying the type of event described. If this is specified, an event will // be dispatched on the browser to the listener for the specified event name; // the website source code should use addEventListener() to listen for named events. // The onmessage handler is called if no event name is specified for a message. Event string `json:"event"` // The data field for the message. When the EventSource receives multiple consecutive lines that begin with data:, // it will concatenate them, inserting a newline character between each one. // Trailing newlines are removed. Data json.RawMessage `json:"data"` // The reconnection time to use when attempting to send the event. This must be an integer, // specifying the reconnection time in milliseconds. // If a non-integer value is specified, the field is ignored. Retry int `json:"retry"` // Contains identifiers of previous nodes this event has been through BeenTo []string `json:"been_to"` }
The Message type represents a server-sent event.
type Status ¶
type Status struct { Goroutines int `json:"num_goroutines"` Gossip struct { MemberCount int `json:"member_count"` Members map[string]int `json:"members"` } `json:"gossip"` Channels map[string][]string `json:"channels"` }
The Status type represents the status of a node/cluster. It contains sections for the gossip memberlist and the node's channels