snorlax

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 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 Exchange added in v1.4.0

func Exchange(exchange string) func(*opts)

Exchange sets default exchange. Default to "amq.Topic".

func PublisherSource added in v1.0.0

func PublisherSource(source string) func(*pubOpts)

func PublisherWrapper

func PublisherWrapper(w PubWrapper) func(*pubOpts)

func QOS added in v1.4.0

func QOS(prefetchCount int) func(*opts)

QOS quality of service prefetch count.

func SubscriberAutoAck

func SubscriberAutoAck() func(*subOpts)

func SubscriberAutoDelete added in v1.3.1

func SubscriberAutoDelete() func(*subOpts)

func SubscriberExclusive added in v1.3.1

func SubscriberExclusive() func(*subOpts)

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 ToContext added in v1.0.0

func ToContext(ctx context.Context, h Headers) context.Context

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 proto.Message) error

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

type HeaderOption added in v1.2.0

type HeaderOption func(Headers)

func HeaderCorrelationID added in v1.2.0

func HeaderCorrelationID(id string) HeaderOption

func HeaderReplyTo added in v1.2.0

func HeaderReplyTo(topic string) HeaderOption

type Headers added in v1.0.0

type Headers map[string]interface{}

func FromContext added in v1.0.0

func FromContext(ctx context.Context) Headers

type Option

type Option func(*opts)

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) MustPublish added in v1.3.1

func (p *Publisher) MustPublish(ctx context.Context, topic string, msg proto.Message, opts ...HeaderOption)

MustPublish same as Publish but panics on error.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, topic string, msg proto.Message, opts ...HeaderOption) 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 and channel to RabbitMQ.

func (*Snorlax) Close

func (s *Snorlax) Close() error

Close amqp connection.

func (*Snorlax) IsClosed added in v1.3.1

func (s *Snorlax) IsClosed() bool

IsClosed checks amqp connection.

func (*Snorlax) MustPublisher added in v1.2.0

func (s *Snorlax) MustPublisher(optsf ...PublisherOption) *Publisher

MustPublisher same as NewPublisher but panics if err not nil.

func (*Snorlax) MustSubscriber added in v1.2.0

func (s *Snorlax) MustSubscriber(optsf ...SubscriberOption) *Subscriber

MustSubscriber same as NewSubscriber but panics if err not nil.

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

func (*Snorlax) QueueUnbind added in v1.4.0

func (s *Snorlax) QueueUnbind(queue, topic string) error

QueueUnbind is shortcut to channel.QueueUnbind.

type SubWrapper

type SubWrapper func(Handler) Handler

type Subscriber

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

Subscriber subscribes to exchange's topic.

func (*Subscriber) MustSubscribe added in v1.3.1

func (s *Subscriber) MustSubscribe(ctx context.Context, topic string, h Handler)

MustSubscribe same as Subscribe but panics on error.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, topic string, h Handler) error

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. Context will be canceled if amqp connection will be closed.

type SubscriberOption

type SubscriberOption func(*subOpts)

Jump to

Keyboard shortcuts

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