Documentation
¶
Overview ¶
Package pubsub implements channel and pattern based publish/subscribe.
Publishing never blocks on subscribers: each Subscriber decides how to deliver (typically by queueing to a per-connection writer) and slow subscribers are dropped by their transport rather than stalling publishers.
Index ¶
- type Hub
- func (h *Hub) Channels(pattern string) []string
- func (h *Hub) NumPat() int
- func (h *Hub) NumSub(channels ...string) []int
- func (h *Hub) PSubscribe(s Subscriber, pattern string) bool
- func (h *Hub) PUnsubscribe(s Subscriber, pattern string) bool
- func (h *Hub) Publish(channel, message string) int
- func (h *Hub) Subscribe(s Subscriber, channel string) bool
- func (h *Hub) Unsubscribe(s Subscriber, channel string) bool
- func (h *Hub) UnsubscribeAll(s Subscriber, channels, patterns []string)
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub routes messages from publishers to subscribers.
func (*Hub) PSubscribe ¶
func (h *Hub) PSubscribe(s Subscriber, pattern string) bool
PSubscribe adds s to a glob pattern.
func (*Hub) PUnsubscribe ¶
func (h *Hub) PUnsubscribe(s Subscriber, pattern string) bool
PUnsubscribe removes s from a pattern.
func (*Hub) Publish ¶
Publish delivers message to subscribers of channel and of matching patterns, returning the number of deliveries.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(s Subscriber, channel string) bool
Subscribe adds s to channel. It reports whether s was newly subscribed.
func (*Hub) Unsubscribe ¶
func (h *Hub) Unsubscribe(s Subscriber, channel string) bool
Unsubscribe removes s from channel.
func (*Hub) UnsubscribeAll ¶
func (h *Hub) UnsubscribeAll(s Subscriber, channels, patterns []string)
UnsubscribeAll removes every subscription of s, e.g. when its connection closes.
type Subscriber ¶
type Subscriber interface {
Deliver(channel, pattern, message string)
}
Subscriber receives published messages. Deliver must not block. pattern is empty for messages received through a channel subscription.