micro/broker/noop.go
Vasiliy Tolstov c062aab1a9
add noop broker and noop store (#30)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-09-03 15:11:05 +03:00

75 lines
1.2 KiB
Go

package broker
type noopBroker struct {
opts Options
}
type noopSubscriber struct {
topic string
opts SubscribeOptions
}
func (n *noopBroker) Init(opts ...Option) error {
for _, o := range opts {
o(&n.opts)
}
return nil
}
func (n *noopBroker) Options() Options {
return n.opts
}
func (n *noopBroker) Address() string {
return ""
}
func (n *noopBroker) Connect() error {
return nil
}
func (n *noopBroker) Disconnect() error {
return nil
}
func (n *noopBroker) Publish(topic string, m *Message, opts ...PublishOption) error {
return nil
}
func (n *noopBroker) Subscribe(topic string, h Handler, opts ...SubscribeOption) (Subscriber, error) {
options := NewSubscribeOptions()
for _, o := range opts {
o(&options)
}
return &noopSubscriber{topic: topic, opts: options}, nil
}
func (n *noopBroker) String() string {
return "noop"
}
func (n *noopSubscriber) Options() SubscribeOptions {
return n.opts
}
func (n *noopSubscriber) Topic() string {
return n.topic
}
func (n *noopSubscriber) Unsubscribe() error {
return nil
}
// newBroker returns a new noop broker
func newBroker(opts ...Option) Broker {
options := NewOptions()
for _, o := range opts {
o(&options)
}
return &noopBroker{opts: options}
}