Documentation
¶
Overview ¶
Package mq is an interface used for asynchronous messaging, the default implementation is kafka
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codecer ¶
type Codecer interface {
Marshal(interface{}) ([]byte, error)
Unmarshal([]byte, interface{}) error
String() string
}
Codec is a simple encoding interface used for the mq/transport
type Event ¶
type Event interface {
// Topic return the topic of the message
Topic() string
// Message return the message body
Message() *Message
// ACK message reply operation
Ack() error
// Error get the error of message consumption
Error() error
// Extra the important information other than the message body
Extra() map[string]interface{}
}
Event is given to a subscription handler for processing.
type Handler ¶
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
Body []byte
// contains filtered or unexported fields
}
Message is the message entity.
func (Message) MessageKey ¶
MessageKey get the flag that represents the message
func (*Message) SetMessageKey ¶
SetMessageKey set a flag that represents the message
type Option ¶
type Option func(*Options)
func ContextWithValue ¶
func ContextWithValue(k, v interface{}) Option
type Options ¶
type Options struct {
Addresses []string
Secure bool
Codec Codecer
// Handler executed when error happens in mq message processing
ErrorHandler Handler
TLSConfig *tls.Config
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
Log *logrus.Entry
}
type PublishOption ¶
type PublishOption func(*PublishOptions)
func PublishContext ¶
func PublishContext(ctx context.Context) PublishOption
PublishContext set context
type PublishOptions ¶
type SubscribeOption ¶
type SubscribeOption func(*SubscribeOptions)
func DisableAutoAck ¶
func DisableAutoAck() SubscribeOption
DisableAutoAck will disable auto acking 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
func SubscribeContext ¶
func SubscribeContext(ctx context.Context) SubscribeOption
SubscribeContext set context
type SubscribeOptions ¶
type SubscribeOptions struct {
// AutoAck defaults to true. When a handler returns
// with a nil error the message is receipt already.
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 ¶
func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions
type Subscriber ¶
type Subscriber interface {
Options() SubscribeOptions
Topic() string
Unsubscribe() error
}
Subscriber is a convenience return type for the Subscribe method.
type TLSConfig ¶
type TLSConfig struct {
// CertFile the optional certificate file for client authentication
CertFile string `json:"cert_file,omitempty"`
// KeyFile the optional key file for client authentication
KeyFile string `json:"key_file,omitempty"`
// CAFile the optional certificate authority file for TLS client authentication
CAFile string `json:"ca_file,omitempty"`
// VerifySSL optional verify ssl certificates chain
VerifySSL bool `json:"verify_ssl,omitempty"`
}