go-micro: github.com/micro/go-micro/broker Index | Files | Directories

package broker

import "github.com/micro/go-micro/broker"

Package broker is an interface used for asynchronous messaging


Package Files

broker.go default.go options.go

func Connect Uses

func Connect() error

func Disconnect Uses

func Disconnect() error

func Init Uses

func Init(opts ...Option) error

func Publish Uses

func Publish(topic string, msg *Message, opts ...PublishOption) error

func String Uses

func String() string

type Broker Uses

type Broker interface {
    Init(...Option) error
    Options() Options
    Address() string
    Connect() error
    Disconnect() error
    Publish(topic string, m *Message, opts ...PublishOption) error
    Subscribe(topic string, h Handler, opts ...SubscribeOption) (Subscriber, error)
    String() string

Broker is an interface used for asynchronous messaging.

var (
    DefaultBroker Broker = NewBroker()

func NewBroker Uses

func NewBroker(opts ...Option) Broker

type Event Uses

type Event interface {
    Topic() string
    Message() *Message
    Ack() error

Event is given to a subscription handler for processing

type Handler Uses

type Handler func(Event) error

Handler is used to process messages via a subscription of a topic. The handler is passed a publication interface which contains the message and optional Ack method to acknowledge receipt of the message.

type Message Uses

type Message struct {
    Header map[string]string
    Body   []byte

type Option Uses

type Option func(*Options)

func Addrs Uses

func Addrs(addrs ...string) Option

Addrs sets the host addresses to be used by the broker

func Codec Uses

func Codec(c codec.Marshaler) Option

Codec sets the codec used for encoding/decoding used where a broker does not support headers

func Registry Uses

func Registry(r registry.Registry) Option

func Secure Uses

func Secure(b bool) Option

Secure communication with the broker

func TLSConfig Uses

func TLSConfig(t *tls.Config) Option

Specify TLS Config

type Options Uses

type Options struct {
    Addrs     []string
    Secure    bool
    Codec     codec.Marshaler
    TLSConfig *tls.Config
    // Registry used for clustering
    Registry registry.Registry
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

type PublishOption Uses

type PublishOption func(*PublishOptions)

type PublishOptions Uses

type PublishOptions struct {
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

type SubscribeOption Uses

type SubscribeOption func(*SubscribeOptions)

func DisableAutoAck Uses

func DisableAutoAck() SubscribeOption

DisableAutoAck will disable auto acking of messages after they have been handled.

func Queue Uses

func Queue(name string) SubscribeOption

Queue sets the name of the queue to share messages on

func SubscribeContext Uses

func SubscribeContext(ctx context.Context) SubscribeOption

SubscribeContext set context

type SubscribeOptions Uses

type SubscribeOptions struct {
    // AutoAck defaults to true. When a handler returns
    // with a nil error the message is acked.
    AutoAck bool
    // Subscribers with the same queue name
    // will create a shared subscription where each
    // receives a subset of messages.
    Queue string

    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

func NewSubscribeOptions Uses

func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions

type Subscriber Uses

type Subscriber interface {
    Options() SubscribeOptions
    Topic() string
    Unsubscribe() error

Subscriber is a convenience return type for the Subscribe method

func Subscribe Uses

func Subscribe(topic string, handler Handler, opts ...SubscribeOption) (Subscriber, error)


memoryPackage memory provides a memory broker
natsPackage nats provides a NATS broker
servicePackage service provides the broker service client

Package broker imports 16 packages (graph) and is imported by 472 packages. Updated 2020-02-11. Refresh now. Tools for package owners.