broadcast: github.com/spiral/broadcast Index | Files | Directories

package broadcast

import "github.com/spiral/broadcast"

Index

Package Files

broker.go client.go config.go memory.go redis.go router.go rpc.go service.go

Constants

const ID = "broadcast"

ID defines public service name.

type Broker Uses

type Broker interface {
    // Serve serves broker.
    Serve() error

    // Stop closes the consumption and disconnects broker.
    Stop()

    // Subscribe broker to one or multiple topics.
    Subscribe(upstream chan *Message, topics ...string) error

    // SubscribePattern broker to pattern.
    SubscribePattern(upstream chan *Message, pattern string) error

    // Unsubscribe broker from one or multiple topics.
    Unsubscribe(upstream chan *Message, topics ...string) error

    // UnsubscribePattern broker from pattern.
    UnsubscribePattern(upstream chan *Message, pattern string) error

    // Publish one or multiple Channel.
    Publish(messages ...*Message) error
}

Broker defines the ability to operate as message passing broker.

type Client Uses

type Client struct {
    // contains filtered or unexported fields
}

Client subscribes to a given topic and consumes or publish messages to it.

func (*Client) Channel Uses

func (c *Client) Channel() chan *Message

Channel returns incoming messages channel.

func (*Client) Close Uses

func (c *Client) Close() (err error)

Close the client and consumption.

func (*Client) Patterns Uses

func (c *Client) Patterns() []string

Patterns return all the patterns client subscribed to.

func (*Client) Publish Uses

func (c *Client) Publish(msg ...*Message) error

Publish message into associated topic or topics.

func (*Client) Subscribe Uses

func (c *Client) Subscribe(topics ...string) error

Subscribe client to specific topics.

func (*Client) SubscribePattern Uses

func (c *Client) SubscribePattern(pattern string) error

SubscribePattern subscribe client to the specific topic pattern.

func (*Client) Topics Uses

func (c *Client) Topics() []string

Topics return all the topics client subscribed to.

func (*Client) Unsubscribe Uses

func (c *Client) Unsubscribe(topics ...string) error

Unsubscribe client from specific topics

func (*Client) UnsubscribePattern Uses

func (c *Client) UnsubscribePattern(pattern string) error

UnsubscribePattern client from topic pattern.

type Config Uses

type Config struct {
    // RedisConfig configures redis broker.
    Redis *RedisConfig
}

Config configures the broadcast extension.

func (*Config) Hydrate Uses

func (c *Config) Hydrate(cfg service.Config) error

Hydrate reads the configuration values from the source configuration.

func (*Config) InitDefaults Uses

func (c *Config) InitDefaults() error

InitDefaults enables in memory broadcast configuration.

type Memory Uses

type Memory struct {
    // contains filtered or unexported fields
}

Memory manages broadcasting in memory.

func (*Memory) Publish Uses

func (m *Memory) Publish(messages ...*Message) error

Publish one or multiple Channel.

func (*Memory) Serve Uses

func (m *Memory) Serve() error

Serve serves broker.

func (*Memory) Stop Uses

func (m *Memory) Stop()

Stop closes the consumption and disconnects broker.

func (*Memory) Subscribe Uses

func (m *Memory) Subscribe(upstream chan *Message, topics ...string) error

Subscribe broker to one or multiple channels.

func (*Memory) SubscribePattern Uses

func (m *Memory) SubscribePattern(upstream chan *Message, pattern string) error

SubscribePattern broker to pattern.

func (*Memory) Unsubscribe Uses

func (m *Memory) Unsubscribe(upstream chan *Message, topics ...string) error

Unsubscribe broker from one or multiple channels.

func (*Memory) UnsubscribePattern Uses

func (m *Memory) UnsubscribePattern(upstream chan *Message, pattern string) error

UnsubscribePattern broker from pattern.

type Message Uses

type Message struct {
    // Topic message been pushed into.
    Topic string `json:"topic"`

    // Payload to be broadcasted. Must be valid json when transferred over RPC.
    Payload json.RawMessage `json:"payload"`
}

Message represent single message.

type Redis Uses

type Redis struct {
    // contains filtered or unexported fields
}

Redis based broadcast Router.

func (*Redis) Publish Uses

func (r *Redis) Publish(messages ...*Message) error

Publish one or multiple Channel.

func (*Redis) Serve Uses

func (r *Redis) Serve() error

Serve serves broker.

func (*Redis) Stop Uses

func (r *Redis) Stop()

Stop closes the consumption and disconnects broker.

func (*Redis) Subscribe Uses

func (r *Redis) Subscribe(upstream chan *Message, topics ...string) error

Subscribe broker to one or multiple channels.

func (*Redis) SubscribePattern Uses

func (r *Redis) SubscribePattern(upstream chan *Message, pattern string) error

SubscribePattern broker to pattern.

func (*Redis) Unsubscribe Uses

func (r *Redis) Unsubscribe(upstream chan *Message, topics ...string) error

Unsubscribe broker from one or multiple channels.

func (*Redis) UnsubscribePattern Uses

func (r *Redis) UnsubscribePattern(upstream chan *Message, pattern string) error

UnsubscribePattern broker from pattern.

type RedisConfig Uses

type RedisConfig struct {
    // Addr of the redis server.
    Addr string

    // Password to redis server.
    Password string

    // DB index.
    DB  int
}

RedisConfig configures redis broker.

type Router Uses

type Router struct {
    // contains filtered or unexported fields
}

Router performs internal message routing to multiple subscribers.

func NewRouter Uses

func NewRouter() *Router

NewRouter creates new topic and pattern router.

func (*Router) Dispatch Uses

func (r *Router) Dispatch(msg *Message)

Dispatch to all connected topics.

func (*Router) Subscribe Uses

func (r *Router) Subscribe(upstream chan *Message, topics ...string) (newTopics []string)

Subscribe to topic and return list of newly assigned topics.

func (*Router) SubscribePattern Uses

func (r *Router) SubscribePattern(upstream chan *Message, pattern string) (newPatterns []string, err error)

SubscribePattern subscribes to glob parent and return true and return array of newly added patterns. Error in case if blob is invalid.

func (*Router) Unsubscribe Uses

func (r *Router) Unsubscribe(upstream chan *Message, topics ...string) (dropTopics []string)

Unsubscribe from given list of topics and return list of topics which are no longer claimed.

func (*Router) UnsubscribePattern Uses

func (r *Router) UnsubscribePattern(upstream chan *Message, pattern string) (dropPatterns []string)

UnsubscribePattern unsubscribe from the pattern and returns an array of patterns which are no longer claimed.

type Service Uses

type Service struct {
    // contains filtered or unexported fields
}

Service manages even broadcasting and websocket interface.

func (*Service) Broker Uses

func (s *Service) Broker() Broker

Broker returns associated broker.

func (*Service) Init Uses

func (s *Service) Init(cfg *Config, rpc *rpc.Service) (ok bool, err error)

Init service.

func (*Service) NewClient Uses

func (s *Service) NewClient() *Client

NewClient returns single connected client with ability to consume or produce into associated topic(svc).

func (*Service) Publish Uses

func (s *Service) Publish(msg ...*Message) error

Publish one or multiple Channel.

func (*Service) Serve Uses

func (s *Service) Serve() (err error)

Serve broadcast broker.

func (*Service) Stop Uses

func (s *Service) Stop()

Stop closes broadcast broker.

Directories

PathSynopsis
tests

Package broadcast imports 9 packages (graph) and is imported by 3 packages. Updated 2020-04-20. Refresh now. Tools for package owners.