msg

package
v2.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package msg contains high level types/interfaces for msg implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SubjectNameRegexp is subject name's format.
	SubjectNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*$`)
)

Functions

func AssertMsgType

func AssertMsgType(spec MsgSpec, msg interface{}) error

AssertMsgType makes sure msg's type conform to the spec: reflect.TypeOf(msg) == spec.MsgType()

Types

type MsgAsyncPublisher

type MsgAsyncPublisher interface {
	// PublishAsync publishes a message to the given subject asynchronously.
	// The final result is returned by `cb` if PublishAsync returns nil.
	// `cb` must be called exactly once in this case.
	PublishAsync(ctx context.Context, spec MsgSpec, msg interface{}, cb func(error)) error
}

MsgAsyncPublisher is similar to MsgPublisher but in async manner. It's trivial to implement MsgPublisher, see MsgAsyncPublisherFunc.

type MsgAsyncPublisherFunc

type MsgAsyncPublisherFunc func(context.Context, MsgSpec, interface{}, func(error)) error

MsgAsyncPublisherFunc is an adapter to allow the use of ordinary functions as MsgAsyncPublisher.

func NewMsgAsyncPublisherWithMWs

func NewMsgAsyncPublisherWithMWs(publisher MsgAsyncPublisher, mws ...MsgAsyncPublisherMiddleware) MsgAsyncPublisherFunc

NewMsgAsyncPublisherWithMWs wraps a MsgAsyncPublisher with middlewares.

func (MsgAsyncPublisherFunc) Publish

func (fn MsgAsyncPublisherFunc) Publish(ctx context.Context, spec MsgSpec, msg interface{}) error

Publish implements MsgAsyncPublisher interface.

func (MsgAsyncPublisherFunc) PublishAsync

func (fn MsgAsyncPublisherFunc) PublishAsync(ctx context.Context, spec MsgSpec, msg interface{}, cb func(error)) error

PublishAsync implements MsgAsyncPublisher interface.

type MsgAsyncPublisherMiddleware

type MsgAsyncPublisherMiddleware func(MsgAsyncPublisherFunc) MsgAsyncPublisherFunc

MsgAsyncPublisherMiddleware wraps MsgAsyncPublisher into another one.

type MsgHandler

type MsgHandler func(context.Context, interface{}) error

MsgHandler handles messages. For 'at least once delivery' implementations, a message should be redelivered if the handler returns an error. Otherwise it may or may not be redelivered.

type MsgMiddleware

type MsgMiddleware func(spec MsgSpec, queue string, handler MsgHandler) MsgHandler

MsgMiddleware wraps a MsgHandler into another one.

type MsgPublisher

type MsgPublisher interface {
	// Publish publishes a message to the given subject. It returns nil if success.
	Publish(ctx context.Context, spec MsgSpec, msg interface{}) error
}

MsgPublisher is used to publish messages.

type MsgPublisherFunc

type MsgPublisherFunc func(context.Context, MsgSpec, interface{}) error

MsgPublisherFunc is an adapter to allow the use of ordinary functions as MsgPublisher.

func NewMsgPublisherWithMWs

func NewMsgPublisherWithMWs(publisher MsgPublisher, mws ...MsgPublisherMiddleware) MsgPublisherFunc

NewMsgPublisherWithMWs wraps a MsgPublisher with middlewares.

func (MsgPublisherFunc) Publish

func (fn MsgPublisherFunc) Publish(ctx context.Context, spec MsgSpec, msg interface{}) error

Publish implements MsgPublisher interface.

type MsgPublisherMiddleware

type MsgPublisherMiddleware func(MsgPublisherFunc) MsgPublisherFunc

MsgPublisherMiddleware wraps MsgPublisher into another one.

type MsgSpec

type MsgSpec interface {
	// SubjectName is the topic.
	SubjectName() string

	// NewMsg generate a new message. Must be a pointer.
	NewMsg() interface{}

	// MsgType returns msg's type.
	MsgType() reflect.Type

	// MsgValue returns a sample msg value, don't modify its content.
	MsgValue() interface{}
}

MsgSpec is the contract between msg publisher and subscriber.

func MustMsgSpec

func MustMsgSpec(subjectName string, newMsg func() interface{}) MsgSpec

MustMsgSpec is must-version of NewMsgSpec.

func MustRawDataMsgSpec

func MustRawDataMsgSpec(subjectName string) MsgSpec

MustRawDataMsgSpec is must-version of NewRawDataMsgSpec.

func NewMsgSpec

func NewMsgSpec(subjectName string, newMsg func() interface{}) (MsgSpec, error)

NewMsgSpec validates and creates a new MsgSpec.

func NewRawDataMsgSpec

func NewRawDataMsgSpec(subjectName string) (MsgSpec, error)

NewRawDataMsgSpec validates and creates a new MsgSpec with *rawenc.RawData msg type.

type MsgSubscriber

type MsgSubscriber interface {
	// Subscribe subscribes to a given subject. One subject can have many queues.
	// In normal case (excpet message redelivery) each message will be delivered to
	// one member of each queue.
	//
	// Order of messages is not guaranteed since redelivery.
	Subscribe(spec MsgSpec, queue string, handler MsgHandler, opts ...interface{}) error
}

MsgSubscriber is used to consume messages.

type MsgSubscriberFunc

type MsgSubscriberFunc func(MsgSpec, string, MsgHandler, ...interface{}) error

MsgSubscriberFunc is an adapter to allow the use of ordinary functions as MsgSubscriber.

func (MsgSubscriberFunc) Subscribe

func (fn MsgSubscriberFunc) Subscribe(spec MsgSpec, queue string, handler MsgHandler, opts ...interface{}) error

Subscribe implements MsgSubscriber interface.

type MsgSubscriberWithMWs

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

MsgSubscriberWithMWs wraps a MsgSubscriber with middlewares.

func NewMsgSubscriberWithMWs

func NewMsgSubscriberWithMWs(subscriber MsgSubscriber, mws ...MsgMiddleware) *MsgSubscriberWithMWs

NewMsgSubscriberWithMWs creates a new MsgSubscriberWithMWs.

func (*MsgSubscriberWithMWs) Subscribe

func (subscriber *MsgSubscriberWithMWs) Subscribe(spec MsgSpec, queue string, handler MsgHandler, opts ...interface{}) error

Subscribe implements MsgSubscriber interface.

Jump to

Keyboard shortcuts

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