mq

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

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageType message type enum
	MessageType = iota
	// MTRequest request =1
	MTRequest = 1
	// MTResponse response = 2
	MTResponse = 2
	// MTNotify notify = 3
	MTNotify = 3
	// MTBroadcast broadcast = 4
	MTBroadcast = 4
	//MTRequestAny request/reply
	MTRequestAny = 5
	//MTResponseAny
	MTResponseAny = 6
	//MTRequestPush  pub/sub
	MTRequestPush = 7
	//MTResponsePush
	MTResponsePush = 8
)
View Source
const (
	// InvalidInt32 Invalid values set to -1
	InvalidInt32 = -1
	// ErrorCodeOK Define error code = 0 if success
	ErrorCodeOK = 0
)
View Source
const (
	// MinSizePower min buffer get from pool, means buf size = 1<<7
	MinSizePower = 7
	// MaxSizePower max buffer get from pool, means buf size = 1<<16
	MaxSizePower = 16
	// OutMaxBufferPower means buffer size > MaxBufferSize
	OutMaxBufferPower = MaxSizePower + 1
	// MinBufferSize buffer size 1 << 6
	MinBufferSize = 1 << MinSizePower
	// MaxBufferSize buffer size 1 << 16
	MaxBufferSize = 1 << MaxSizePower
)
View Source
const MaxIDSequence = 10

MaxIDSequence max srcid sequence

Variables

This section is empty.

Functions

func CreatePool

func CreatePool(size uint8) *sync.Pool

CreatePool []byte pool

func RemoveMessage

func RemoveMessage(m *Message)

RemoveMessage return message to pool

Types

type BytesPool

type BytesPool struct {
	Pools []*sync.Pool
}

BytesPool alloc and manger buffer

var GBytesPool *BytesPool

GBytesPool pre-create []byte pool

func NewBytesPool

func NewBytesPool() *BytesPool

NewBytesPool create buffer pool

func (*BytesPool) Alloc

func (p *BytesPool) Alloc(size int32) []byte

Alloc borrow buffer from pool,if size > MaxBufferSize, dynamic alloc buffer

func (*BytesPool) CalcIndex

func (p *BytesPool) CalcIndex(size int32) int32

CalcIndex get the pool index,if size > MaxBufferSize, return OutMaxBufferPower

func (*BytesPool) Free

func (p *BytesPool) Free(buf []byte)

Free return buffer to pool

type Message

type Message struct {
	MsgID     int32
	SrcID     int32
	DestID    int32
	SessionID string
	MsgType   int8
	Cmd       string
	Body      proto.Message
	ErrCode   int32
}

Message mq Message

func CreateMessage

func CreateMessage(msgID int32, srcID int32, destID int32, msgType int8, cmd string, sessionID string) *Message

CreateMessage get message from pool

func (*Message) Reset

func (m *Message) Reset()

Reset message set to default value

func (*Message) SetBody

func (m *Message) SetBody(body proto.Message)

SetBody set message body

type MessagePool

type MessagePool struct {
	Pool *sync.Pool
}

MessagePool mamager message objests

var GMessagePool *MessagePool

GMessagePool pre-create message pool

func GMQ

func GMQ() *MessagePool

GMQ session instance

func NewMessagePool

func NewMessagePool() *MessagePool

NewMessagePool new message pool

func (*MessagePool) Alloc

func (p *MessagePool) Alloc(msgID int32, srcID int32, destID int32, msgType int8, cmd string, sessionID string) *Message

Alloc borrow message from pool

func (*MessagePool) Free

func (p *MessagePool) Free(m *Message)

Free retrun message to pool

Jump to

Keyboard shortcuts

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