broker

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package broker defines standard interface for a message broker.

Index

Constants

This section is empty.

Variables

View Source
var File_broker_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Broker

type Broker interface {
	// Open establish connection to the target server.
	Open(ctx context.Context) error
	// Publish publish the message to the target topic.
	Publish(ctx context.Context, topic string, m *Message, opts ...PublishOption) error
	// Subscribe subscribe to the topic to consume messages.
	Subscribe(ctx context.Context, topic string, h Handler, opts ...SubscribeOption) (Subscriber, error)
	// Close flush all in-flight messages and close underlying connection.
	// Close allows a context to control the duration
	// of a flush/close call. This context should be non-nil.
	// If a deadline is not set, a default deadline of 5s will be applied.
	Close(context.Context) error
}

Broker is an interface used for asynchronous messaging.

type Event

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

Event is given to a subscription handler for processing

type Handler

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

type Message struct {
	Header map[string]string `` /* 153-byte string literal not displayed */
	Body   []byte            `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
	// contains filtered or unexported fields
}

func (*Message) Descriptor deprecated

func (*Message) Descriptor() ([]byte, []int)

Deprecated: Use Message.ProtoReflect.Descriptor instead.

func (*Message) GetBody

func (x *Message) GetBody() []byte

func (*Message) GetHeader

func (x *Message) GetHeader() map[string]string

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) ProtoReflect

func (x *Message) ProtoReflect() protoreflect.Message

func (*Message) Reset

func (x *Message) Reset()

func (*Message) String

func (x *Message) String() string

type PublishOption

type PublishOption func(*PublishOptions)

PublishOption is a func for config publish options.

type PublishOptions

type PublishOptions struct {
}

PublishOptions is a configuration holder for publish options.

type Reason

type Reason int
const (
	ReasonUnmarshalFailure Reason = iota
	ReasonSubscriptionFailure
)

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

SubscribeOption is a func for config subscription.

func DisableAutoAck

func DisableAutoAck() SubscribeOption

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

func Queue

func Queue(name string) SubscribeOption

Queue sets the name of the queue to share messages on

type SubscribeOptions

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
}

SubscribeOptions is a configuration holder for subscriptions.

func (*SubscribeOptions) Apply

func (op *SubscribeOptions) Apply(opts ...SubscribeOption)

Apply apply the options.

type Subscriber

type Subscriber interface {
	Topic() string
	Unsubscribe() error
}

Subscriber is a convenience return type for the Subscribe method

Directories

Path Synopsis
Package memory provides a message broker using memory.
Package memory provides a message broker using memory.

Jump to

Keyboard shortcuts

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