Documentation ¶
Overview ¶
Package nats provide a message broker using NATS.
Index ¶
- Variables
- type Config
- type Nats
- func (n *Nats) Close(ctx context.Context) error
- func (n *Nats) Connect() error
- func (n *Nats) HealthCheck() health.CheckFunc
- func (n *Nats) Publish(topic string, m *broker.Message, opts ...broker.PublishOption) error
- func (n *Nats) Subscribe(topic string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMissingEncoder report the encoder is missing. ErrMissingEncoder = errors.New("nats: missing encoder") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Addrs string `envconfig:"NATS_ADDRS" default:"nats:4222"` Encoder string `envconfig:"NATS_ENCODER" 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.
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) Close ¶ added in v0.1.2
Close flush in-flight messages and close the underlying connection.
func (*Nats) HealthCheck ¶
HealthCheck return a health check func.
type Option ¶ added in v0.0.9
type Option func(*Nats)
Option is an optional configuration.
func Address ¶ added in v0.1.0
Address is an option to set target addresses of NATS server. Multiple addresses are separated by comma.
func FromConfig ¶ added in v0.1.0
FromConfig is an option to create new broker from an existing config.
func FromEnv ¶ added in v0.0.9
func FromEnv(opts ...config.ReadOption) Option
FromEnv is an option to create new broker base on environment variables.
Click to show internal directories.
Click to hide internal directories.