Documentation ¶
Overview ¶
Package msg contains high level types/interfaces for msg implementations.
Index ¶
- Variables
- func AssertMsgType(spec MsgSpec, msg interface{}) error
- type MsgAsyncPublisher
- type MsgAsyncPublisherFunc
- type MsgAsyncPublisherMiddleware
- type MsgHandler
- type MsgMiddleware
- type MsgPublisher
- type MsgPublisherFunc
- type MsgPublisherMiddleware
- type MsgSpec
- type MsgSubscriber
- type MsgSubscriberFunc
- type MsgSubscriberWithMWs
Constants ¶
This section is empty.
Variables ¶
var ( // SubjectNameRegexp is subject name's format. SubjectNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)*$`) )
Functions ¶
func AssertMsgType ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
MustMsgSpec is must-version of NewMsgSpec.
func MustRawDataMsgSpec ¶
MustRawDataMsgSpec is must-version of NewRawDataMsgSpec.
func NewMsgSpec ¶
NewMsgSpec validates and creates a new MsgSpec.
func NewRawDataMsgSpec ¶
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.