client

package
v0.0.0-...-1df5a02 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESP_MESSAGE = 101
	RESP_ERROR   = 102
	RESP_RESULT  = 103
)

Variables

View Source
var (
	ErrTopicEmpty   = errors.New("topic is empty")
	ErrTopicChannel = errors.New("channel is empty")
)

Functions

func Example_Ack

func Example_Ack(c *Client, topic, msgId, bindKey string)

确认已消费消息

func Example_Consume

func Example_Consume(c *Client, topic, bindKey string)

消费消息

func Example_Dead_back

func Example_Dead_back(c *Client, topic string, num int)

死信

func Example_DelcareQueue

func Example_DelcareQueue(c *Client, topic, bindKey string)

声明队列

func Example_Loop_Consume

func Example_Loop_Consume(c *Client, topic, bindKey string)

轮询模式消费消息 当server端没有消息后,sleep 3秒后再次请求

func Example_Produce

func Example_Produce(c *Client, topic string, num int, routeKey string)

生产消息

func Example_Publish

func Example_Publish(c *Client, channel, message string)

发布消息

func Example_Subscribe

func Example_Subscribe(c *Client, channel string)

订阅消息

Types

type Client

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

func GetClientByAvgMode

func GetClientByAvgMode(endpoints string) *Client

平均模式

func GetClientByRandomMode

func GetClientByRandomMode(endpoints string) *Client

随机模式

func GetClientByWeightMode

func GetClientByWeightMode(endpoints string) *Client

权重模式

func InitClients

func InitClients(endpoints string) ([]*Client, error)

初始化客户端,建立和注册中心节点连接

func NewClient

func NewClient(addr string, weight int) *Client

func (*Client) Ack

func (c *Client) Ack(topic, msgId, bindKey string) error

Ack 确认已消费消息 ack <message_id> <topic> <bind_key>\n

func (*Client) Dead

func (c *Client) Dead(topic, bindKey string) ([]byte, error)

Dead 消费消息 dead <topic_name> <bind_key>

func (*Client) Dead_back

func (c *Client) Dead_back(topic string, num int) error

死信

func (*Client) Declare

func (c *Client) Declare(topic, bindKey string) ([]byte, error)

Declare declare queue queue <topic_name> <bind_key>\n

func (*Client) Exit

func (c *Client) Exit()

func (*Client) GetAddr

func (c *Client) GetAddr() string

GetAddr 获取客户端连接的节点地址

func (*Client) Mpush

func (c *Client) Mpush(topic string, msgs []MMsgPkg, routeKey string) ([]uint64, error)

Mpush 批量生产消息 mpub <topic_name> <num> <msg.len> <[]byte({"delay":1,"body":"xxx","topic":"xxx","routeKey":"xxx"})> <msg.len> <[]byte({"delay":1,"body":"xxx","topic":"xxx","routeKey":"xxx"})>

func (*Client) Ping

func (c *Client) Ping() ([]byte, error)

Set 设置topic配置 set <topic> <is_auto_ack> <mode> <msgTTR> <msgRetry>

func (*Client) Pop

func (c *Client) Pop(topic, bindKey string) ([]byte, error)

Pop 消费消息 pop <topic_name> <bind_key>

func (*Client) Publish

func (c *Client) Publish(channel, message string) error

Publish 发布消息 publish <channel_name>\n <message_len> <message>

func (*Client) Push

func (c *Client) Push(pkg MsgPkg) ([]byte, error)

Push 生产消息 pub <topic_name> <route_key> <delay-time> [ 4-byte size in bytes ][ N-byte binary data ]

func (*Client) Receive

func (c *Client) Receive() (int, []byte)

func (*Client) Set

func (c *Client) Set(topic string, isAutoAck, mode, msgTTR, msgRetry int) ([]byte, error)

Set 设置topic配置 set <topic> <is_auto_ack> <mode> <msgTTR> <msgRetry>

func (*Client) Subscribe

func (c *Client) Subscribe(channel string) error

Subscribe 订阅频道 subscribe <channel_name> <message>\n

type MMsgPkg

type MMsgPkg struct {
	Body  string
	Delay int
}

type MsgPkg

type MsgPkg struct {
	Body     string `json:"body"`
	Topic    string `json:"topic"`
	Delay    int    `json:"delay"`
	RouteKey string `json:"route_key"`
}

type RespMsgData

type RespMsgData struct {
	Id    string `json:"id"`
	Body  string `json:"body"`
	Retry uint16 `json:"retry_count"`
}

Jump to

Keyboard shortcuts

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