npub

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 2 Imported by: 0

README

npub

nats的推送消息客户端。


安装

go get -u github.com/zhufuyi/pkg/nats/npub


使用示例

    var natsAddr = []string{"nats://192.168.101.88:4222"}

	err := npub.Init(natsAddr)  // 连接

	err := npub.GetClient().PushString("foo.string", []byte(msg))  // 发送字符串

	err := npub.GetClient().PushJSON("foo.json", &msg)   // 发送对象

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(natsAddr []string) error

Init nats初始化

Types

type Client

type Client struct {
	Conn *nats.Conn
}

Client nats连接套接字

func GetClient

func GetClient() *Client

GetClient 获取nats操作对象

func (*Client) Close

func (n *Client) Close()

Close 关闭

func (*Client) PushJSON

func (n *Client) PushJSON(topic string, v interface{}) error

PushJSON 推送json数据,注:参数v必须为引用或指针

func (*Client) PushString

func (n *Client) PushString(topic string, msg []byte) error

PushString 推送字符串数据

Jump to

Keyboard shortcuts

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