common

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EMPTY     = "EMPTY"     //无数据
	HEARTBEAT = "HEARTBEAT" //心跳
)
View Source
const (
	Version = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Msg

type Msg struct {
	Header MsgHeader
	Body   MsgBody
}

func FailMsg

func FailMsg(topic string, errorInfo string) *Msg

func NewMsg

func NewMsg(Header MsgHeader,
	Body MsgBody) *Msg

func ReadMsg

func ReadMsg(reader io.Reader) (*Msg, error)

func ResponseMsg

func ResponseMsg(topic string, payload []byte) *Msg

func SuccessMsg

func SuccessMsg(topic string) *Msg

func (*Msg) ByteSize

func (m *Msg) ByteSize() uint32

func (*Msg) Bytes

func (msg *Msg) Bytes() []byte

func (*Msg) Copy

func (msg *Msg) Copy() *Msg

func (*Msg) InitLength

func (msg *Msg) InitLength()

func (*Msg) IsHeartbeat added in v1.0.0

func (msg *Msg) IsHeartbeat() bool

func (*Msg) String

func (msg *Msg) String() string

func (*Msg) WriteTo

func (m *Msg) WriteTo(w io.Writer) (int64, error)

WriteTo 将消息写入writer

type MsgBody

type MsgBody struct {
	TopicLen   uint32
	PayloadLen uint32 // Payload长度
	Topic      []byte

	Payload []byte // 消息内容
}

type MsgHeader

type MsgHeader struct {
	Version        uint32
	Type           MsgType
	BodyLen        uint32 // 消息体长度
	ExpireAfterNow uint32 // 相对有效期,单位ms,真实的有效截至时间=消息接收方的now() + ExpireAfterNow, 0表示永久有效
	ClientId       uint32 // 客户端标识
}

type MsgType

type MsgType int32
const (
	POST_WAIT_RESPONSE MsgType = iota // 请求,并等待服务器响应(客户端推送消息后需要等待并接收服务端的处理结果)
	POST_NO_RESPONSE                  // 请求,不需要服务器响应(客户端推送消息后不需要等待服务端的处理结果,防止网络I/O阻塞)
	RESPONSE                          // 服务器响应
	QUERY                             // 查询消息队列
	QUERY_POP                         // 查询消息队列,并删除消息
	QUERY_STREAM                      // 查询消息队列,返回消息流,每个消息只会被一个消费者消费
	QUERY_STREAM_GROUP                // 查询消息队列,返回消息流,每个消息可以被多个消费者消费
)

func (MsgType) IsPost added in v1.1.0

func (mt MsgType) IsPost() bool

IsPost 是否是post类型的消息

func (MsgType) IsQuery added in v1.1.1

func (mt MsgType) IsQuery() bool

IsQuery 是否是query类型的消息

func (MsgType) IsQueryStream added in v1.1.0

func (mt MsgType) IsQueryStream() bool

IsQueryStream 是否是query stream类型的消息

func (MsgType) NeedReplyToClient added in v1.1.0

func (mt MsgType) NeedReplyToClient() bool

NeedReplyToClient 是否需要向客户端响应

func (MsgType) String

func (msgType MsgType) String() string

Jump to

Keyboard shortcuts

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