resurrect broker event (#26)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -14,7 +14,15 @@ type Broker interface {
|
||||
}
|
||||
|
||||
// Handler is used to process messages via a subscription of a topic.
|
||||
type Handler func(*Message) error
|
||||
type Handler func(Event) error
|
||||
|
||||
// Event is given to a subscription handler for processing
|
||||
type Event interface {
|
||||
Topic() string
|
||||
Message() *Message
|
||||
Ack() error
|
||||
Error() error
|
||||
}
|
||||
|
||||
// Message is used to transfer data
|
||||
type Message struct {
|
||||
|
@@ -9,8 +9,6 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
AutoAck bool
|
||||
|
||||
Addrs []string
|
||||
Secure bool
|
||||
Codec codec.Marshaler
|
||||
@@ -26,6 +24,12 @@ type Options struct {
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
func NewOptions() Options {
|
||||
return Options{
|
||||
Context: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
type PublishOptions struct {
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
@@ -63,7 +67,10 @@ func PublishContext(ctx context.Context) PublishOption {
|
||||
type SubscribeOption func(*SubscribeOptions)
|
||||
|
||||
func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
|
||||
opt := SubscribeOptions{}
|
||||
opt := SubscribeOptions{
|
||||
AutoAck: true,
|
||||
Context: context.Background(),
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
@@ -87,6 +94,14 @@ func Codec(c codec.Marshaler) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// SubscribeAutoAck will disable auto acking of messages
|
||||
// after they have been handled.
|
||||
func SubscribeAutoAck(b bool) SubscribeOption {
|
||||
return func(o *SubscribeOptions) {
|
||||
o.AutoAck = b
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorHandler will catch all broker errors that cant be handled
|
||||
// in normal way, for example Codec errors
|
||||
func ErrorHandler(h Handler) Option {
|
||||
|
Reference in New Issue
Block a user