Documentation ¶
Index ¶
- Constants
- type Callback
- type Codec
- type CodecOption
- type Event
- type ExponentialBackoff
- type Handler
- type Middleware
- type OnEvent
- type OnEventOption
- type OnEventOptions
- type Publish
- type Queue
- func (q *Queue) Close() error
- func (q *Queue) OnError(callback func(err error)) error
- func (q *Queue) OnEvent(eventName string, options ...OnEventOption) *OnEvent
- func (q *Queue) Publish(eventName string) *Publish
- func (q *Queue) Start() error
- func (q *Queue) UseOnEvent(m Middleware) *Queue
- func (q *Queue) UsePublish(m Middleware) *Queue
Constants ¶
const ( DefaultMaxElapsedTime = 1 * time.Minute DefaultMaxInterval = 5 * time.Second DefaultRandomizationFactor = 0.5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface { // Name returns the name of the encoder, for debugging purposes. Name() string // NewEvent returns an empty event that can be marshalled into. NewEvent() codecEvent // Encode marshals the event into a byte stream. Encode(codecEvent) ([]byte, error) // Decode unmarhals a byte stream into a codecEvent. Decode(data []byte) (codecEvent, error) }
Codec is an interface for marshaling/unmarshaling event body and headers.
func JSONCodec ¶
func JSONCodec(opts ...CodecOption) Codec
JSONCodec returns a codec that marshals both headers and body into a json object.
type CodecOption ¶
type CodecOption func(*codecSettings)
func UseTag ¶
func UseTag(tag string) CodecOption
UseTag option can be used to change the struct tag used for marshaling/unmarshaling (default is json).
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is the public representation of a geb event, used for both Publish and OnEvent.
func (*Event) Context ¶
Context returns the event's context. Publish and OnEvent does NOT use this context, meaning that context cancel does NOT work. Middlewares should communicate through the context.
func (*Event) SetContext ¶
SetContext can be used for setting the event's context. Publish and OnEvent does NOT use this context, meaning that context cancel does NOT work. Middlewares should communicate through the context.
type ExponentialBackoff ¶
type ExponentialBackoff struct {
// contains filtered or unexported fields
}
func NewExponentialBackOff ¶
func NewExponentialBackOff(maxElapsedTime, maxInterval time.Duration, randomizationFactor float64) *ExponentialBackoff
func (*ExponentialBackoff) NextBackOff ¶
func (b *ExponentialBackoff) NextBackOff() (bool, time.Duration)
type Handler ¶
type Handler interface { // Start must be called after OnError, but before any Publish/OnEvent calls are made. Start() error // Close can be called to gracefully close the queue. No new events will be processed, // but existing event processings will continue. Publishing on a closed handler will return with an error. Close() error // OnError callback is called when a non-event specific (not a marshaling/unmarshaling) error occurs. // eg: connection error OnError(cb func(err error)) error // OnEvent for msgpack and json codecs, either 'codec' or 'json' tags may be used OnEvent(eventName string, callback func(payload []byte) error, options OnEventOptions) error // Publish for msgpack and json codecs, either 'codec' or 'json' tags may be used Publish(eventName string, payload []byte) error }
Handler is an interface for the actual messaging implementation.
type Middleware ¶
Middleware is the signature of middlewares. Middlewares are layered (like an onion), meaning that the last added middleware will be executed first. You should always call next() from the middleware. If next() is not called, none of the inner (previously added) middlewares will run.
func RecoveryMiddleware ¶
func RecoveryMiddleware() Middleware
func RetryMiddleware ¶
func RetryMiddleware() Middleware
type OnEvent ¶
type OnEvent struct {
// contains filtered or unexported fields
}
OnEvent is the struct for building OnEvent subscriptions.
func (*OnEvent) Codec ¶
Codec can be used to set the codec for the OnEvent. By default the codec is inherited from the queue.
func (*OnEvent) Listen ¶
Listen starts the OnEvent subscription, using the configuration and middlewares stored in the OnEvent object. All middlewares MUST be registered before calling Listen.
func (*OnEvent) Use ¶
func (oe *OnEvent) Use(m Middleware) *OnEvent
Use a middleware for this specific OnEvent processing. Also see: geb.Middleware.
type OnEventOption ¶
type OnEventOption func(oe *OnEventOptions)
func MaxGoroutines ¶
func MaxGoroutines(maxGoroutines int) OnEventOption
MaxGoroutines sets the maximum number of concurrent OnEvent callbacks for a given eventName. Default is 1.
type OnEventOptions ¶
type OnEventOptions struct {
MaxGoroutines int
}
OnEventOptions contains the options for event subscriptions (should be supported by Handler implementations.) This should NOT be used directly, instead use methods with OnEventOption return type.
type Publish ¶
type Publish struct {
// contains filtered or unexported fields
}
Publish is the struct for preparing publishes.
func (*Publish) Codec ¶
Codec can be used to set the codec for the Publish. By default the codec is inherited from the queue.
func (*Publish) Context ¶
Context sets the Publish context. It runs before any middlewares, so all middlewares will have access to this context.
func (*Publish) Do ¶
Do publishes the event, using the configuration and middlewares stored in the Publish object. All middlewares MUST be registered before calling Do.
func (*Publish) Use ¶
func (p *Publish) Use(m Middleware) *Publish
Use a middleware for this specific Publish. Also see: geb.Middleware.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is the main struct for the geb client. You can publish/listen to multiple event types on a single queue.
func (*Queue) Close ¶
Close can be called to gracefully close the queue. No new events will be processed, but existing event processings will continue. Publishing on a closed queue will return with an error.
func (*Queue) OnError ¶
OnError callback is called when a non-event specific (not a marshaling/unmarshaling) error occurs. eg: connection error
func (*Queue) OnEvent ¶
func (q *Queue) OnEvent(eventName string, options ...OnEventOption) *OnEvent
OnEvent returns a builder for an OnEvent subscription. Add all the necessary middlewares, then call Listen(callback).
func (*Queue) Publish ¶
Publish returns a builder for a Publish call. Add all the necessary middlewares, then call Do() for actually publishing the event.
func (*Queue) Start ¶
Start must be called after OnError, but before any Publish/OnEvent calls are made.
func (*Queue) UseOnEvent ¶
func (q *Queue) UseOnEvent(m Middleware) *Queue
UseOnEvent adds a middleware for all OnEvent processings. To add a middleware to a specific OnEvent only, call OnEvent.Use() instead. Also see: geb.Middleware.
func (*Queue) UsePublish ¶
func (q *Queue) UsePublish(m Middleware) *Queue
UsePublish adds a middleware for all Publish calls. To add a middleware to a specific Publish only, call Publish.Use() instead. Also see: geb.Middleware.