mmq

package
v0.0.0-...-5a8ff1d Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFullTopic indicates this topic is full, and can not put anymore.
	ErrFullTopic = errors.New("full topic")

	// ErrClosedTopic indicates put to closed topic
	ErrClosedTopic = errors.New("closed topic")

	// ErrInvalidMsg indicates an invalid message
	ErrInvalidMsg = errors.New("invalid message")

	// ErrTooLargeMsg indicates message length exceed the max cap.
	ErrTooLargeMsg = errors.New("too large message")
)
View Source
var DefaultConfig = &Config{
	QueueCap: 8000,
	TopicCap: 2 << 20,
	MsgCap:   1 << 10,
}

DefaultConfig use up to 16GB memory with max 8000 topics, 2MB per topic, 1KB per message.

View Source
var (
	// ErrOutOfTopic indicates can not create topics anymore.
	ErrOutOfTopic = errors.New("out of topic")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	QueueCap int // max num of topics a queue can hold
	TopicCap int // max memory size of messages a topic can hold
	MsgCap   int // max length of a message
}

Config the message queue.

type Message

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

Message can be put to or get from a topic.

func NewMessage

func NewMessage(b []byte) *Message

NewMessage create a message

func (*Message) Data

func (m *Message) Data() []byte

Data returns the real data.

func (*Message) ID

func (m *Message) ID() uint32

ID returns the crc32 of message.

type Queue

type Queue struct {
	*Config
	// contains filtered or unexported fields
}

Queue can have many topics, all messages are kept in memory.

func NewQueue

func NewQueue(cfg *Config) (q *Queue, err error)

NewQueue create a message queue in memory.

func (*Queue) Get

func (q *Queue) Get(id string) (t *Topic, err error)

Get returns a topic from queue, will create a new one if is not exist.

func (*Queue) Topics

func (q *Queue) Topics() (res []*Topic)

Topics returns all topics in this queue.

type Topic

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

Topic is a FIFO queue to put and get messages.

func (*Topic) Close

func (t *Topic) Close() (err error)

Close marks this topic as closed. Message can not be put to this topic after closed, but is still able to read pending messages.

func (*Topic) Count

func (t *Topic) Count() int

Count returns all message had been put to this topic

func (*Topic) Drop

func (t *Topic) Drop(m *Message) error

Drop should only be called after Peek and with the right message

func (*Topic) Get

func (t *Topic) Get() (m *Message, err error)

Get returns a message in topic and drop it.

func (*Topic) ID

func (t *Topic) ID() string

ID returns unique topic id

func (*Topic) Peek

func (t *Topic) Peek() (m *Message, err error)

Peek only returns the message, won't drop it.

func (*Topic) Pending

func (t *Topic) Pending() int

Pending returns messages can be get.

func (*Topic) Put

func (t *Topic) Put(m *Message) (err error)

Put a message to this topic.

Jump to

Keyboard shortcuts

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