Documentation
¶
Overview ¶
Package events is for event streaming and storage
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingTopic is returned if a blank topic was provided to publish ErrMissingTopic = errors.New("Missing topic") // ErrEncodingMessage is returned from publish if there was an error encoding the message option ErrEncodingMessage = errors.New("Error encoding message") )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// ID to uniquely identify the event
ID string
// Topic of event, e.g. "registry.service.created"
Topic string
// Timestamp of the event
Timestamp time.Time
// Metadata contains the values the event was indexed by
Metadata map[string]string
// Payload contains the encoded message
Payload []byte
// contains filtered or unexported fields
}
Event is the object returned by the broker when you subscribe to a topic
func (*Event) Nack ¶
Nack negatively acknowledges processing of the event (i.e. failure) in ManualAck mode
func (*Event) SetAckFunc ¶
func (*Event) SetNackFunc ¶
type PublishOption ¶
type PublishOption func(o *PublishOptions)
PublishOption sets attributes on PublishOptions
func WithMetadata ¶
func WithMetadata(md map[string]string) PublishOption
WithMetadata sets the Metadata field on PublishOptions
func WithTimestamp ¶
func WithTimestamp(t time.Time) PublishOption
WithTimestamp sets the timestamp field on PublishOptions
type PublishOptions ¶
type PublishOptions struct {
// Metadata contains any keys which can be used to query the data, for example a customer id
Metadata map[string]string
// Timestamp to set for the event, if the timestamp is a zero value, the current time will be used
Timestamp time.Time
}
PublishOptions contains all the options which can be provided when publishing an event
type ReadOption ¶
type ReadOption func(o *ReadOptions)
ReadOption sets attributes on ReadOptions
func ReadLimit ¶
func ReadLimit(l uint) ReadOption
ReadLimit sets the limit attribute on ReadOptions
func ReadOffset ¶
func ReadOffset(l uint) ReadOption
ReadOffset sets the offset attribute on ReadOptions
type ReadOptions ¶
type ReadOptions struct {
// Limit the number of results to return
Limit uint
// Offset the results by this number, useful for paginated queries
Offset uint
}
ReadOptions contains all the options which can be provided when reading events from a store
type Store ¶
type Store interface {
Read(topic string, opts ...ReadOption) ([]*Event, error)
Write(event *Event, opts ...WriteOption) error
}
Store is an event store interface
type Stream ¶
type Stream interface {
Publish(topic string, msg interface{}, opts ...PublishOption) error
Subscribe(topic string, opts ...SubscribeOption) (<-chan Event, error)
}
Stream is an event streaming interface
type SubscribeOption ¶
type SubscribeOption func(o *SubscribeOptions)
SubscribeOption sets attributes on SubscribeOptions
func WithAutoAck ¶
func WithAutoAck(ack bool, ackWait time.Duration) SubscribeOption
WithAutoAck sets the AutoAck field on SubscribeOptions and an ackWait duration after which if no ack is received the message is requeued in case auto ack is turned off
func WithQueue ¶
func WithQueue(q string) SubscribeOption
WithQueue sets the Queue fielf on SubscribeOptions to the value provided
func WithRetryLimit ¶
func WithRetryLimit(retries int) SubscribeOption
WithRetryLimit sets the RetryLimit field on SubscribeOptions. Set to -1 for infinite retries (default)
func WithStartAtTime ¶
func WithStartAtTime(t time.Time) SubscribeOption
WithStartAtTime sets the StartAtTime field on SubscribeOptions to the value provided
type SubscribeOptions ¶
type SubscribeOptions struct {
// Queue is the name of the subscribers queue, if two subscribers have the same queue the message
// should only be published to one of them
Queue string
// StartAtTime is the time from which the messages should be consumed from. If not provided then
// the messages will be consumed starting from the moment the Subscription starts.
StartAtTime time.Time
// AutoAck if true (default true), automatically acknowledges every message so it will not be redelivered.
// If false specifies that each message need ts to be manually acknowledged by the subscriber.
// If processing is successful the message should be ack'ed to remove the message from the stream.
// If processing is unsuccessful the message should be nack'ed (negative acknowledgement) which will mean it will
// remain on the stream to be processed again.
AutoAck bool
AckWait time.Duration
// RetryLimit indicates number of times a message is retried
RetryLimit int
// CustomRetries indicates whether to use RetryLimit
CustomRetries bool
}
SubscribeOptions contains all the options which can be provided when subscribing to a topic
func (SubscribeOptions) GetRetryLimit ¶
func (s SubscribeOptions) GetRetryLimit() int
type WriteOption ¶
type WriteOption func(o *WriteOptions)
WriteOption sets attributes on WriteOptions
func WithTTL ¶
func WithTTL(d time.Duration) WriteOption
WithTTL sets the TTL attribute on WriteOptions
type WriteOptions ¶
type WriteOptions struct {
// TTL is the duration the event should be recorded for, a zero value TTL indicates the event should
// be stored indefinately
TTL time.Duration
}
WriteOptions contains all the options which can be provided when writing an event to a store