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 `toml:"port"`
// Path for HTTP broadast
Path string `toml:"path"`
// Secret token to authorize requests
Secret string `toml:"secret"`
// 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 `toml:"cors_headers"`
// CORSHosts contains a list of hostnames for CORS (comma-separated)
CORSHosts string `toml:"cors_hosts"`
}
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
func (HTTPConfig) ToToml ¶ added in v1.5.4
func (c HTTPConfig) ToToml() string
type LegacyNATSBroadcaster ¶
type LegacyNATSBroadcaster struct {
// contains filtered or unexported fields
}
func NewLegacyNATSBroadcaster ¶
func NewLegacyNATSBroadcaster(node Handler, c *LegacyNATSConfig, 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 LegacyNATSConfig ¶ added in v1.5.4
type LegacyNATSConfig struct {
Channel string `toml:"channel"`
NATS *nconfig.NATSConfig `toml:"nats"`
}
func NewLegacyNATSConfig ¶ added in v1.5.4
func NewLegacyNATSConfig() LegacyNATSConfig
func (LegacyNATSConfig) ToToml ¶ added in v1.5.4
func (c LegacyNATSConfig) ToToml() string
type LegacyRedisBroadcaster ¶
type LegacyRedisBroadcaster struct {
// contains filtered or unexported fields
}
LegacyRedisBroadcaster contains information about Redis pubsub connection
func NewLegacyRedisBroadcaster ¶
func NewLegacyRedisBroadcaster(node Handler, config *LegacyRedisConfig, 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 LegacyRedisConfig ¶ added in v1.5.4
type LegacyRedisConfig struct {
Channel string `toml:"channel"`
Redis *rconfig.RedisConfig `toml:"redis"`
}
func NewLegacyRedisConfig ¶ added in v1.5.4
func NewLegacyRedisConfig() LegacyRedisConfig
func (LegacyRedisConfig) ToToml ¶ added in v1.5.4
func (c LegacyRedisConfig) ToToml() string
type RedisBroadcaster ¶
type RedisBroadcaster struct {
// contains filtered or unexported fields
}
RedisBroadcaster represents Redis broadcaster using Redis streams
func NewRedisBroadcaster ¶
func NewRedisBroadcaster(node Handler, config *RedisConfig, l *slog.Logger) *RedisBroadcaster
NewRedisBroadcaster builds a new RedisSubscriber struct
func (*RedisBroadcaster) IsFanout ¶
func (s *RedisBroadcaster) IsFanout() bool
func (*RedisBroadcaster) Start ¶
func (s *RedisBroadcaster) Start(done chan error) error
type RedisConfig ¶ added in v1.5.4
type RedisConfig struct {
Stream string `toml:"stream"`
Group string `toml:"group"`
// Redis stream read wait time in milliseconds
StreamReadBlockMilliseconds int64 `toml:"stream_read_block_milliseconds"`
Redis *rconfig.RedisConfig `toml:"redis"`
}
func NewRedisConfig ¶ added in v1.5.4
func NewRedisConfig() RedisConfig
func (RedisConfig) ToToml ¶ added in v1.5.4
func (c RedisConfig) ToToml() string