firehose

package
v0.0.0-...-34c5bf1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements the Publish and Subscribe interfaces

func NewClient

func NewClient(opts *ClientOptions) *Client

NewClient returns a new Firehose client

func (*Client) GetName

func (c *Client) GetName() string

GetName returns a friendly name for the process

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, channel string, message interface{}) error

Publish emits a message to the firehose

func (*Client) Start

func (c *Client) Start(ctx context.Context) error

Start listens for messages on the firehose

func (*Client) Subscribe

func (c *Client) Subscribe(channel string, handler Handler)

Subscribe registers the handler against the channel. If a handler already exists, the function will panic.

type ClientOptions

type ClientOptions struct {
	Group    string
	Consumer string
	Redis    *redis.Client

	// HandlerTimeout is the duration after which the
	// context passed to handlers is cancelled. If this
	// value is zero, a default duration of 30s is applied.
	HandlerTimeout time.Duration
}

ClientOptions contains fields to configure the Firehose client

type Decoder

type Decoder func(v interface{}) error

Decoder is a function that decodes an event into v

type Handler

type Handler interface {
	HandleEvent(ctx context.Context, decode Decoder) Result
}

Handler processes messages received on a channel that has been subscribed to. HandleEvent should return a result that tells the client whether the handling was successful or not.

type HandlerFunc

type HandlerFunc func(ctx context.Context, decode Decoder) Result

HandlerFunc is an adapter that allows ordinary functions to be used as event handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func (HandlerFunc) HandleEvent

func (f HandlerFunc) HandleEvent(ctx context.Context, decode Decoder) Result

HandleEvent calls f(ctx, decode)

type MockClient

type MockClient struct {
}

MockClient can be used by unit tests

func (MockClient) Publish

func (m MockClient) Publish(context.Context, string, interface{}) error

Publish does nothing

func (MockClient) Subscribe

func (m MockClient) Subscribe(string, Handler)

Subscribe is not implemented

type Publisher

type Publisher interface {
	// Publish emits an event to the firehose
	Publish(ctx context.Context, channel string, message interface{}) error
}

Publisher is the interface that wraps the publish method

type Result

type Result queuer.Result

Result is an alias for queuer.Result

func Discard

func Discard(err error) Result

Discard should be returned when the event was not successfully processed but should not be retried

func Fail

func Fail(err error) Result

Fail should be returned when the event was not successfully processed and should be retried

func Success

func Success() Result

Success should be returned when the event was successfully processed.

type Subscriber

type Subscriber interface {
	Subscribe(channel string, handler Handler)
}

Subscriber is the interface that wraps the subscribe method

Jump to

Keyboard shortcuts

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