Documentation ¶
Index ¶
- Variables
- type Client
- type HandlerFunc
- type Message
- func (m *Message) Complete() error
- func (m *Message) DecodePayload(v interface{}) error
- func (m *Message) Defer(dur time.Duration) error
- func (m *Message) Discard() error
- func (m *Message) EncodePayload(v interface{}) error
- func (m *Message) Extend(dur time.Duration) error
- func (m *Message) Push() error
- func (m *Message) PushDelay(dur time.Duration) error
- type State
Constants ¶
This section is empty.
Variables ¶
var ErrNoMessage = sql.ErrNoRows
ErrNoMessage is returned when a Message cannot be found. It will be returned when you try to find a Message by id and it does not exist, or when you try to Pop from an empty topic.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a PushPop client with a connection pool to a backend PostgreSQL database which will be used for message persistence.
func NewClient ¶
NewClient creates a new Client for the given PostgreSQL database connection url. It will automatically create or update tables or indices as necessary.
func (*Client) FindMessage ¶
FindMessage finds a message by its primary identifier, a string representation of a 16-byte UUID. The ErrNoMessage error will be returned if the message does not exist.
func (*Client) NewMessage ¶
NewMessage creates (but does not enqueue) a new Message with the given topic and optional payload.
type HandlerFunc ¶
HandlerFunc is a function that takes a Message and performs some work. In case of an error, the message will be reqeueued.
type Message ¶
type Message struct { // Id is the UUID of the message, useful for looking up by id. Id string // Topic is the name of the topic the message has or will be queued in. Topic string // State represent the state of the Message. State State // StateTime represents a timestamp to be interpreted based on the State: // State_READY: The earliest time at which the message can be popped. // State_PENDING: The deadline by which the consumer must check-in, either // completing, discarding, deferring, or extending. // State_COMPLETED: The time the message was completed. // State_DISCARDED: The time the message was discarded. StateTime time.Time // Payload is a byte slice payload containing the message contents. Payload []byte // contains filtered or unexported fields }
Message represents a single message that can be pushed or popped by a Client. While in posession of a client, Messages are stateless.
func (*Message) Complete ¶
Complete marks the message as complete, meaning all work has been performed and the message can be safely deleted.
func (*Message) DecodePayload ¶
DecodePayload decodes the JSON payload of the message into the given object.
func (*Message) Discard ¶
Discard marks the message as discarded, meaning the work was not performed but the message has no further value and can be safely deleted.
func (*Message) EncodePayload ¶
EncodePayload encodes the given object as JSON and stores it in the Payload field of the Message.
type State ¶
type State uint16
State represents the status of a message. A message can only be in one state at a time.
const ( // READY: The message is enqueued and ready for processing. State_READY State = 0 // PENDING: The message was popped and is in-flight with a consumer. State_PENDING State = 1 // COMPLETED: The message was popped and successfully processed. At this // point the message is safe to delete. State_COMPLETED State = 2 // DISCARDED: The message was popped and otherwise processed. At this point // the message is safe to delete. State_DISCARDED State = 3 )