snorlax

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 11 Imported by: 0

README

Snorlax

GitHub Workflow Status (branch) GoDoc

Documentation

Overview

Package snorlax provides tools for message query based microservices:

  • Configuration through environment;
  • Logging through standard log;
  • Use only one transport = amqp through RabbitMQ;
  • Use only one exchange type for all = topic;

No registry, service discovery and other smart things. Let k8s do the rest.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSubNoMessageType      = errors.New("no message type")
	ErrSubUnknownMessageType = errors.New("unknown message type")
	ErrSubUnmarshaling       = errors.New("failed to unmarshal message")
)

Functions

func PublisherExchange

func PublisherExchange(exchange string) func(*pubOpts)

PublisherExchange. Defaults to "amq.topic".

func PublisherNotDurable

func PublisherNotDurable() func(*pubOpts)

func PublisherQueue

func PublisherQueue(queue string) func(*pubOpts)

func PublisherWrapper

func PublisherWrapper(w PubWrapper) func(*pubOpts)

func SubscriberAutoAck

func SubscriberAutoAck() func(*subOpts)

func SubscriberExchange

func SubscriberExchange(exchange string) func(*subOpts)

SubscriberExchange. Defaults to "amq.topic".

func SubscriberNotDurable

func SubscriberNotDurable() func(*subOpts)

func SubscriberQueue

func SubscriberQueue(queue string) func(*subOpts)

func SubscriberWrapper

func SubscriberWrapper(w SubWrapper) func(*subOpts)

func TLS

func TLS(t *tls.Config) func(*opts)

TLS config to RabbitMQ connection.

func URL

func URL(url string) func(*opts)

URL to RabbitMQ. Ex: amqp://guest:guest@0.0.0.0:5672/ AMQP_URL will be used if this option not provided.

Types

type Handler

type Handler func(ctx context.Context, msg interface{}) error

Handler handles messages from subscriber. Msg always proto.Message and will be parsed to specific one based on "MessageType" header.

type Option

type Option func(*opts)

func DeclareExchange

func DeclareExchange(name string) Option

DeclareExchange on Snorlax initialization. Always topic and always durable.

type PubFn

type PubFn func(context.Context, string, proto.Message) error

type PubWrapper

type PubWrapper func(PubFn) PubFn

type Publisher

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

Publisher publish proto messages.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, topic string, msg proto.Message) error

Publish proto message to specific topic. Messages always persistent. Message type will be in header in "MessageType" key.

type PublisherOption

type PublisherOption func(*pubOpts)

type Snorlax

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

Snorlax is main point for creating pubs and subs.

func New

func New(optsf ...Option) (*Snorlax, error)

New creates connection to RabbitMQ, declare exchanges if any etc.

func (*Snorlax) Close

func (s *Snorlax) Close() error

Close amqp connection.

func (*Snorlax) NewPublisher

func (s *Snorlax) NewPublisher(optsf ...PublisherOption) (*Publisher, error)

NewPublisher creates channel to RabbitMQ.

func (*Snorlax) NewSubscriber

func (s *Snorlax) NewSubscriber(optsf ...SubscriberOption) (*Subscriber, error)

NewSubscriber creates channel to RabbitMQ

type SubFn

type SubFn func(context.Context, string, Handler) <-chan SubStatus

type SubStatus

type SubStatus struct {
	Exchange    string
	Queue       string
	Topic       string
	MessageType string
	ContentType string
	Error       error
}

SubStatus from Subscriber. Useful for metrics and logging.

type SubWrapper

type SubWrapper func(SubFn) SubFn

type Subscriber

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

Subscriber subscribes to exchange's topic.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, topic string, h Handler) <-chan SubStatus

Subscribe to topic with handler. Blocking function. If message can't be parsed with MessageType header into proto, message will be rejected. On error in handler will be rejected and requeued.

type SubscriberOption

type SubscriberOption func(*subOpts)

func SubscribeThrottlingInterval added in v0.2.0

func SubscribeThrottlingInterval(duration string) SubscriberOption

Jump to

Keyboard shortcuts

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