Broker init
This commit is contained in:
@@ -38,11 +38,11 @@ type Subscriber interface {
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultBroker Broker = newHttpBroker([]string{})
|
||||
DefaultBroker Broker = newHttpBroker()
|
||||
)
|
||||
|
||||
func NewBroker(addrs []string, opt ...Option) Broker {
|
||||
return newHttpBroker(addrs, opt...)
|
||||
func NewBroker(opts ...Option) Broker {
|
||||
return newHttpBroker(opts...)
|
||||
}
|
||||
|
||||
func Init(opts ...Option) error {
|
||||
|
||||
@@ -9,6 +9,6 @@ func init() {
|
||||
cmd.DefaultBrokers["http"] = NewBroker
|
||||
}
|
||||
|
||||
func NewBroker(addrs []string, opts ...broker.Option) broker.Broker {
|
||||
return broker.NewBroker(addrs, opts...)
|
||||
func NewBroker(opts ...broker.Option) broker.Broker {
|
||||
return broker.NewBroker(opts...)
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func newTransport(config *tls.Config) *http.Transport {
|
||||
return t
|
||||
}
|
||||
|
||||
func newHttpBroker(addrs []string, opts ...Option) Broker {
|
||||
func newHttpBroker(opts ...Option) Broker {
|
||||
options := Options{
|
||||
Context: context.TODO(),
|
||||
}
|
||||
@@ -102,8 +102,8 @@ func newHttpBroker(addrs []string, opts ...Option) Broker {
|
||||
}
|
||||
|
||||
addr := ":0"
|
||||
if len(addrs) > 0 && len(addrs[0]) > 0 {
|
||||
addr = addrs[0]
|
||||
if len(options.Addrs) > 0 && len(options.Addrs[0]) > 0 {
|
||||
addr = options.Addrs[0]
|
||||
}
|
||||
|
||||
reg, ok := options.Context.Value(registryKey).(registry.Registry)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestBroker(t *testing.T) {
|
||||
m := mock.NewRegistry()
|
||||
b := NewBroker([]string{}, Registry(m))
|
||||
b := NewBroker(Registry(m))
|
||||
|
||||
if err := b.Init(); err != nil {
|
||||
t.Errorf("Unexpected init error: %v", err)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Addrs []string
|
||||
Secure bool
|
||||
TLSConfig *tls.Config
|
||||
|
||||
@@ -60,6 +61,13 @@ func newSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
|
||||
return opt
|
||||
}
|
||||
|
||||
// Addrs sets the host addresses to be used by the broker
|
||||
func Addrs(addrs ...string) Option {
|
||||
return func(o *Options) {
|
||||
o.Addrs = addrs
|
||||
}
|
||||
}
|
||||
|
||||
// DisableAutoAck will disable auto acking of messages
|
||||
// after they have been handled.
|
||||
func DisableAutoAck() SubscribeOption {
|
||||
|
||||
Reference in New Issue
Block a user