pubee

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2019 License: MIT Imports: 5 Imported by: 0

README

pubee

CircleCI GoDoc GitHub release codecov Go Report Card GitHub

Example

Google Cloud Pub/Sub
ctx := context.Background()

// Initiailze a driver for Google Cloud Pub/Sub
driver, err := cloudpubsub.CreateDriver(
	ctx, "my-gcp-project", "your-topic",
	cloudpubsub.WithCreateTopicIfNeeded(),  // Create a topic when it does not exist
	cloudpubsub.WithDeleteTopicOnClose(),   // Delete the topic on close the publisher
)
if err != nil {
	// ...
}

// Initialize a new publisher instance
publisher := pubee.New(driver,
	pubee.WithJSON(),  // publish messages as JSON
	pubee.WithMetadata("content_type", "json"),
	pubee.WithInterceptors(
		// ...
	}),
	pubee.WithOnFailPublish(func(msg *pubee.Message, err error) {
		// This function is called when failed to publish a message.
	}),
)
defer publisher.Close()

type Book struct {
	Title  string `json:"title"`
}

// Publish a message!
publisher.Publish(ctx, &Book{Title: "The Go Programming Language"})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PublishOpts       []PublishOption
	ErrorLog          Logger
	Interceptor       Interceptor
	OnFailPublishFunc func(*Message, error)
}

type Driver

type Driver interface {
	Publish(context.Context, *Message) <-chan error
	Flush()
	Close(context.Context) error
}

type Engine

type Engine interface {
	Publish(context.Context, interface{}, ...PublishOption)
	Close(context.Context) error
}

func New

func New(d Driver, opts ...Option) Engine

type Interceptor

type Interceptor func(context.Context, *Message, func(context.Context, *Message))

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
	Print(v ...interface{})
}

Logger is the interface for logging

func GetErrorLog

func GetErrorLog(ctx context.Context) Logger

type Message

type Message struct {
	Data     []byte
	Metadata map[string]string
	Original interface{}
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithErrorLog

func WithErrorLog(l Logger) Option

func WithInterceptors

func WithInterceptors(interceptors ...Interceptor) Option

func WithOnFailPublish

func WithOnFailPublish(f func(*Message, error)) Option

type OptionFunc

type OptionFunc func(*Config)

type PublishConfig

type PublishConfig struct {
	Metadata map[string]string
	Marshal  marshal.Func
}

type PublishOption

type PublishOption interface {
	Option
	// contains filtered or unexported methods
}

func WithJSON

func WithJSON() PublishOption

func WithMarshalFunc

func WithMarshalFunc(f marshal.Func) PublishOption

func WithMetadata

func WithMetadata(kv ...string) PublishOption

func WithMetadataMap

func WithMetadataMap(meta map[string]string) PublishOption

func WithProtobuf

func WithProtobuf() PublishOption

type PublishOptionFunc

type PublishOptionFunc func(*PublishConfig)

Directories

Path Synopsis
drivers

Jump to

Keyboard shortcuts

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