2020-09-03 15:11:05 +03:00
|
|
|
package broker
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
import "context"
|
|
|
|
|
|
|
|
type NoopBroker struct {
|
2020-09-03 15:11:05 +03:00
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopSubscriber struct {
|
|
|
|
topic string
|
|
|
|
opts SubscribeOptions
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
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-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) Options() Options {
|
2020-09-03 15:11:05 +03:00
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) Address() string {
|
2020-09-03 15:11:05 +03:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) Connect(ctx context.Context) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) Disconnect(ctx context.Context) error {
|
2020-09-03 15:11:05 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
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-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) Subscribe(ctx context.Context, topic string, h Handler, opts ...SubscribeOption) (Subscriber, error) {
|
2020-09-03 15:11:05 +03:00
|
|
|
options := NewSubscribeOptions()
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &noopSubscriber{topic: topic, opts: options}, nil
|
|
|
|
}
|
|
|
|
|
2020-10-16 09:38:57 +03:00
|
|
|
func (n *NoopBroker) String() string {
|
2020-09-03 15:11:05 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *noopSubscriber) Options() SubscribeOptions {
|
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *noopSubscriber) Topic() string {
|
|
|
|
return n.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
|
|
|
|
}
|