XNats

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 11 Imported by: 0

README

XNats Starter

基于 https://github.com/nats-io/nats.go

Nats Documentation

Documentation https://docs.nats.io

XNats Starter Usage
goinfras.RegisterStarter(XNats.NewStarter())

XNats Config Setting
// Nats Mq 消息系统
type Config struct {
	Switch      bool
	NatsServers []natsServer
}

// 可配集群
type natsServer struct {
	Host       string
	Port       int
	AuthSwitch bool
	UserName   string
	Password   string
}

XNats Usage

详细可查看run_test.go

// 连接池资源实例调用
XNats.XPool()

// 资源组件闭包执行
err := XNats.XF(func(c *nats.Conn) error {
    // TODO
})

// 通用管道方法实例
XNats.XCommonNatsChan()

// 通用发布订阅方法实例
XNats.XCommonNatsPubSub()

// 基于队列组的主题订阅方法实例
XNats.XCommonNatsQueue()

// 基于请求响应方式的通用方法实例
XNats.XCommonNatsRequest()

Documentation

Index

Constants

View Source
const DefaultConnSize = 20

默认初始的连接数

Variables

This section is empty.

Functions

func CreateDefaultPool

func CreateDefaultPool(config *Config) error

func NewStarter

func NewStarter() *starter

func XCommonNatsChan

func XCommonNatsChan() *commonNatsChan

通用管道方法实例

func XCommonNatsPubSub

func XCommonNatsPubSub() *commonNatsPubSub

通用发布订阅方法实例

func XCommonNatsQueue

func XCommonNatsQueue() *commonNatsQueue

基于队列组的主题订阅方法实例

func XCommonNatsRequest

func XCommonNatsRequest() *commonNatsRequest

基于请求响应方式的通用方法实例

func XF

func XF(f func(c *nats.Conn) error) error

资源组件闭包执行

Types

type Config

type Config struct {
	NatsServers []natsServer
}

Nats Mq 消息系统

func DefaultConfig

func DefaultConfig() *Config

type DialFunc

type DialFunc func(natsServersUrl string, options ...nats.Option) (*nats.Conn, error)

连接处理函数

type EncodedMsgHandler

type EncodedMsgHandler func(subject string, goDataMsg interface{})

接收已编码消息的订阅,用于订阅发布go类型数据消息的主题 除接收处理函数不同,其他都一样,请自定义接收消息的数据类型,消息用json编码发送

type NatsPool

type NatsPool struct {
	Network string
	Addr    string
	// contains filtered or unexported fields
}

nats连接池值类型

func NewDefaultPool

func NewDefaultPool(addr string) (*NatsPool, error)

默认连接池的工厂方法

func NewNatsConnectPool

func NewNatsConnectPool(addr string, connSize int, dialFunc DialFunc) (*NatsPool, error)

创建连接池的工厂方法

func NewPool

func NewPool(cfg *Config) (*NatsPool, error)

func XPool

func XPool() *NatsPool

资源组件实例调用

func (*NatsPool) Avail

func (p *NatsPool) Avail() int

有效的连接数

func (*NatsPool) Close

func (p *NatsPool) Close()

func (*NatsPool) Empty

func (p *NatsPool) Empty()

情况连接池

func (*NatsPool) Get

func (p *NatsPool) Get() (*nats.Conn, error)

从连接池获取连接

func (*NatsPool) Put

func (p *NatsPool) Put(conn *nats.Conn)

将连接放回连接池

Jump to

Keyboard shortcuts

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