nats

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDrainTimeout 默认超时时间
	DefaultDrainTimeout = 300
	// DefaultConnectTimeout 建立连接超时时间
	DefaultConnectTimeout = 2
	// DefaultReconnectWait 重连超时时间
	DefaultReconnectWait = 2
	// DefaultMaxReconnect 重试的次数
	DefaultMaxReconnect = 60
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker todo

func NewBroker

func NewBroker(conf *Config) (*Broker, error)

NewBroker todo

func (*Broker) Connect

func (b *Broker) Connect() error

Connect 实现连接

func (*Broker) Debug

func (b *Broker) Debug(l logger.Logger)

Debug 设置Logger

func (*Broker) Disconnect

func (b *Broker) Disconnect() error

Disconnect 断开连接

func (*Broker) Pub

func (b *Broker) Pub(topic string, e *event.Event) error

Pub 发布事件

func (*Broker) Sub

func (b *Broker) Sub(topic string, h bus.EventHandler) error

Sub 订阅事件

type Config

type Config struct {
	Servers        []string `json:"servers,omitempty" yaml:"servers" toml:"servers" env:"NATS_SERVERS" envSeparator:"," validate:"required"`
	DrainTimeout   int      `json:"drain_timeout" yaml:"drain_timeout" toml:"drain_timeout" env:"NATS_DRAIN_TIMEOUT"`         // 单位秒
	ConnectTimeout int      `json:"connect_timeout" yaml:"connect_timeout" toml:"connect_timeout" env:"NATS_CONNECT_TIMEOUT"` // 单位秒
	ReconnectWait  int      `json:"reconnect_wait" ymal:"reconnect_wait" toml:"reconnect_wait" env:"NATS_RECONNECT_WAIT"`     // 单位秒
	MaxReconnect   int      `json:"max_reconnect" yaml:"max_reconnect" toml:"max_reconnect" env:"NATS_MAX_RECONNECT"`         // 最大重连次数
	Username       string   `json:"user_name" yaml:"user_name" toml:"user_name" env:"NATS_USERNAME"`                          // 用户名
	Password       string   `json:"password" yaml:"password" toml:"password" env:"NATS_PASSWORD"`                             // 密码
	Token          string   `json:"token" yaml:"token" toml:"token" env:"NATS_TOKEN"`                                         // 连接Token
}

Config 配置

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig 默认配置

func (*Config) GetConnectTimeout

func (c *Config) GetConnectTimeout() time.Duration

GetConnectTimeout todo

func (*Config) GetDrainTimeout

func (c *Config) GetDrainTimeout() time.Duration

GetDrainTimeout todo

func (*Config) GetMaxReconnect

func (c *Config) GetMaxReconnect() int

GetMaxReconnect todo

func (*Config) GetReconnectWait

func (c *Config) GetReconnectWait() time.Duration

GetReconnectWait todo

func (*Config) Validate

func (c *Config) Validate() error

Validate 配置校验

Jump to

Keyboard shortcuts

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