Documentation ¶
Overview ¶
Package nats provide a message broker using NATS.
Index ¶
- type Config
- type Nats
- func (n *Nats) CheckHealth(ctx context.Context) error
- func (n *Nats) Close(ctx context.Context) error
- func (n *Nats) Open(ctx context.Context) error
- func (n *Nats) Publish(ctx context.Context, topic string, m *broker.Message, ...) error
- func (n *Nats) Subscribe(ctx context.Context, topic string, h broker.Handler, ...) (broker.Subscriber, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Addrs string `envconfig:"NATS_ADDRS" default:"nats://localhost:4222"` Codec string `envconfig:"NATS_CODEC" default:"proto"` Timeout time.Duration `envconfig:"NATS_TIMEOUT" default:"10s"` Username string `envconfig:"NATS_USERNAME"` Password string `envconfig:"NATS_PASSWORD"` }
Config hold common NATS configurations.
func ReadConfigFromEnv ¶
func ReadConfigFromEnv(opts ...config.ReadOption) Config
ReadConfigFromEnv read NATS configuration from environment variables.
type Nats ¶
type Nats struct {
// contains filtered or unexported fields
}
Nats is an implementation of broker.Broker using NATS.
func New ¶
New return a new NATs message broker. If address is not set, default address "nats:4222" will be used.
func (*Nats) CheckHealth ¶
CheckHealth implements health.Checker.
type Option ¶
type Option func(*Nats)
Option is an optional configuration.
func Address ¶
Address is an option to set target addresses of NATS server. Multiple addresses are separated by comma.
func FromConfig ¶
FromConfig is an option to create new broker from an existing config.
func FromEnv ¶
func FromEnv(opts ...config.ReadOption) Option
FromEnv is an option to create new broker base on environment variables.