broadcast

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

This package contains different message broadcast handler implemenentations. Broadcast handler is responsible for consumeing broadcast messages from the outer world and routing them to the application node.

NOTE: There could be multiple broadcast handlers running at the same time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster interface {
	Start(done chan (error)) error
	Shutdown(ctx context.Context) error
	// Returns true if the broadcaster fan-outs the same event
	// to all nodes. Such subscriber shouldn't be used with real pub/sub
	// engines (which are responsible for message distribution)
	IsFanout() bool
}

type HTTPBroadcaster

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

HTTPBroadcaster represents HTTP broadcaster

func NewHTTPBroadcaster

func NewHTTPBroadcaster(node Handler, config *HTTPConfig, l *slog.Logger) *HTTPBroadcaster

NewHTTPBroadcaster builds a new HTTPSubscriber struct

func (*HTTPBroadcaster) Handler

func (s *HTTPBroadcaster) Handler(w http.ResponseWriter, r *http.Request)

Handler processes HTTP requests

func (HTTPBroadcaster) IsFanout

func (HTTPBroadcaster) IsFanout() bool

func (*HTTPBroadcaster) Prepare added in v1.5.0

func (s *HTTPBroadcaster) Prepare() error

Prepare configures the broadcaster to make it ready to accept requests (i.e., calculates the authentication token, etc.)

func (*HTTPBroadcaster) Shutdown

func (s *HTTPBroadcaster) Shutdown(ctx context.Context) error

Shutdown stops the HTTP server

func (*HTTPBroadcaster) Start

func (s *HTTPBroadcaster) Start(done chan (error)) error

Start creates an HTTP server or attaches a handler to the existing one

type HTTPConfig

type HTTPConfig struct {
	// Port to listen on
	Port int
	// Path for HTTP broadast
	Path string
	// Secret token to authorize requests
	Secret string
	// SecretBase is a secret used to generate a token if none provided
	SecretBase string
	// AddCORSHeaders enables adding CORS headers (so you can perform broadcast requests from the browser)
	// (We mostly need it for Stackblitz)
	AddCORSHeaders bool
	// CORSHosts contains a list of hostnames for CORS (comma-separated)
	CORSHosts string
}

HTTPConfig contains HTTP pubsub adapter configuration

func NewHTTPConfig

func NewHTTPConfig() HTTPConfig

NewHTTPConfig builds a new config for HTTP pub/sub

func (*HTTPConfig) IsSecured added in v1.5.0

func (c *HTTPConfig) IsSecured() bool

type Handler

type Handler interface {
	// Handle broadcast message delivered only to this node (and pass it through the broker)
	// (Used by single-node broadcasters)
	HandleBroadcast(json []byte)
	// Handle broadcast message delivered to all nodes
	// (Used by fan-out broadcasters)
	HandlePubSub(json []byte)
}

type LegacyNATSBroadcaster

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

func NewLegacyNATSBroadcaster

func NewLegacyNATSBroadcaster(node Handler, c *nconfig.NATSConfig, l *slog.Logger) *LegacyNATSBroadcaster

func (LegacyNATSBroadcaster) IsFanout

func (LegacyNATSBroadcaster) IsFanout() bool

func (*LegacyNATSBroadcaster) Shutdown

func (s *LegacyNATSBroadcaster) Shutdown(ctx context.Context) error

func (*LegacyNATSBroadcaster) Start

func (s *LegacyNATSBroadcaster) Start(done chan (error)) error

type LegacyRedisBroadcaster

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

LegacyRedisBroadcaster contains information about Redis pubsub connection

func NewLegacyRedisBroadcaster

func NewLegacyRedisBroadcaster(node Handler, config *rconfig.RedisConfig, l *slog.Logger) *LegacyRedisBroadcaster

NewLegacyRedisBroadcaster returns new RedisSubscriber struct

func (LegacyRedisBroadcaster) IsFanout

func (LegacyRedisBroadcaster) IsFanout() bool

func (*LegacyRedisBroadcaster) Shutdown

func (s *LegacyRedisBroadcaster) Shutdown(ctx context.Context) error

Shutdown is no-op for Redis

func (*LegacyRedisBroadcaster) Start

func (s *LegacyRedisBroadcaster) Start(done chan (error)) error

Start connects to Redis and subscribes to the pubsub channel if sentinels is set it gets the the master address first

type RedisBroadcaster

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

RedisBroadcaster represents Redis broadcaster using Redis streams

func NewRedisBroadcaster

func NewRedisBroadcaster(node Handler, config *rconfig.RedisConfig, l *slog.Logger) *RedisBroadcaster

NewRedisBroadcaster builds a new RedisSubscriber struct

func (*RedisBroadcaster) IsFanout

func (s *RedisBroadcaster) IsFanout() bool

func (*RedisBroadcaster) Shutdown

func (s *RedisBroadcaster) Shutdown(ctx context.Context) error

func (*RedisBroadcaster) Start

func (s *RedisBroadcaster) Start(done chan error) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL