2020-09-03 15:11:05 +03:00
|
|
|
package broker
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
import "context"
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
type noopBroker struct {
|
2020-09-03 15:11:05 +03:00
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopSubscriber struct {
|
|
|
|
topic string
|
|
|
|
opts SubscribeOptions
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// NewBroker returns new noop broker
|
|
|
|
func NewBroker(opts ...Option) Broker {
|
|
|
|
return &noopBroker{opts: NewOptions(opts...)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init initialize broker
|
|
|
|
func (n *noopBroker) Init(opts ...Option) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Options returns broker Options
|
|
|
|
func (n *noopBroker) Options() Options {
|
2020-09-03 15:11:05 +03:00
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Address returns broker address
|
|
|
|
func (n *noopBroker) Address() string {
|
2020-09-03 15:11:05 +03:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Connect connects to broker
|
|
|
|
func (n *noopBroker) Connect(ctx context.Context) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Disconnect disconnects from broker
|
|
|
|
func (n *noopBroker) Disconnect(ctx context.Context) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Publish publishes message to broker
|
|
|
|
func (n *noopBroker) Publish(ctx context.Context, topic string, m *Message, opts ...PublishOption) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Subscribe subscribes to broker topic
|
|
|
|
func (n *noopBroker) Subscribe(ctx context.Context, topic string, h Handler, opts ...SubscribeOption) (Subscriber, error) {
|
|
|
|
options := NewSubscribeOptions(opts...)
|
2020-09-03 15:11:05 +03:00
|
|
|
return &noopSubscriber{topic: topic, opts: options}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// String return broker string representation
|
|
|
|
func (n *noopBroker) String() string {
|
2020-09-03 15:11:05 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Options returns subscriber options
|
2020-09-03 15:11:05 +03:00
|
|
|
func (n *noopSubscriber) Options() SubscribeOptions {
|
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// TOpic returns subscriber topic
|
2020-09-03 15:11:05 +03:00
|
|
|
func (n *noopSubscriber) Topic() string {
|
|
|
|
return n.topic
|
|
|
|
}
|
|
|
|
|
2020-11-03 01:08:23 +03:00
|
|
|
// Unsubscribe unsbscribes from broker topic
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *noopSubscriber) Unsubscribe(ctx context.Context) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|