Vasiliy Tolstov
14c97d59c1
* add many options helpers * fix noop client to allow publish messages to topic in broker * fix noop server to allow registering in registry * fix noop server to allow subscribe to topic in broker * fix new service initialization Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package broker
|
|
|
|
import "context"
|
|
|
|
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(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (n *NoopBroker) Disconnect(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (n *NoopBroker) Publish(ctx context.Context, topic string, m *Message, opts ...PublishOption) error {
|
|
return nil
|
|
}
|
|
|
|
func (n *NoopBroker) Subscribe(ctx context.Context, 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(ctx context.Context) error {
|
|
return nil
|
|
}
|