internal

package module
v0.0.0-...-7a995b8 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: MIT Imports: 2 Imported by: 0

README

redis_stream

operates on redis stream

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

type Broker struct {
	Client *redis.Client
}

Broker implements a broker for message publish and subscribe

func (*Broker) XPub

func (s *Broker) XPub(msg *Message, maxLen int) (res string, err error)

XPub publishes a message to a channel. The channel is specified in the header of the message. It returns the result in string.

func (*Broker) XSub

func (s *Broker) XSub(stream, lastID string, blockTime int) (recv *Receiver, err error)

XSub subscribe a stream channel. It expects to receive messages whose ID > lastID. It returns a receiver pointer.

type Message

type Message struct {
	ID     string `json:"id"`     // message ID
	Stream string `json:"stream"` // stream to subscribe
	Body   string `json:"body"`   // message body in JSON-like text
}

Message has header and body, where header contains ID and stream channel name. Body is defined as an interface.

type Receiver

type Receiver struct {
	Stream   string       // stream to receive from
	LastID   string       // last ID we have checked
	Messages chan Message // message queue for receiving
	Shutdown func() error // function to shutdown the receiver
}

Receiver receives messages

Jump to

Keyboard shortcuts

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