Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
func Client(s bandmaster.Service) *nats.Conn
Client returns the underlying `nats.Conn` of the given service.
It assumes that the service is ready; i.e. it might return nil if it's actually not.
NOTE: This will panic if `s` is not a `nats.Service`.
func Config ¶
func Config(s bandmaster.Service) *nats.Options
Config returns the underlying `nats.Options` of the given service.
NOTE: This will panic if `s` is not a `nats.Service`.
func New ¶
func New(opts *nats.Options) bandmaster.Service
New creates a new NATS service using the provided `nats.Options`. You may use the helpers for environment-based configuration to get a pre-configured `nats.Options` with sane defaults.
It doesn't open any connection nor does it do any kind of I/O; i.e. it cannot fail.
Types ¶
type Env ¶
type Env struct {
Addrs []string `envconfig:"ADDRS" default:"nats://localhost:4222"`
AllowReconnect bool `envconfig:"ALLOW_RECONNECT" default:"true"`
MaxReconnect int `envconfig:"MAX_RECONNECT" default:"60"`
ReconnectWait time.Duration `envconfig:"RECONNECT_WAIT" default:"2s"`
Timeout time.Duration `envconfig:"TIMEOUT" default:"2s"`
PingInterval time.Duration `envconfig:"PING_INTERVAL" default:"2m"`
MaxPingsOut int `envconfig:"MAX_PINGS_OUT" default:"2"`
SubChanLen int `envconfig:"SUBCHAN_LEN" default:"8192"`
ReconnectBufSize int `envconfig:"RECONNECT_BUFSIZE" default:"8388608"` // 8MB
DialerTimeout time.Duration `envconfig:"DIALER_TIMEOUT" default:"2s"`
}
Env can be used to configure a NATS session via the environment.
It comes with sane defaults for a local development set-up.
type Service ¶
type Service struct {
*bandmaster.ServiceBase // "inheritance"
// contains filtered or unexported fields
}
Service implements a NATS service based on the 'nats-io/nats' package.
func (*Service) Start ¶
Start opens a connection and PINGs the server: if everything goes smoothly, the service is marked as 'started'; otherwise, an error is returned.
Start is used by BandMaster's internal machinery, it shouldn't ever be called directly by the end-user of the service.