Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-03-24 23:19:12 +03:00
parent eef3064f39
commit 4eae208e72
2 changed files with 27 additions and 127 deletions

27
nats.go
View File

@@ -19,11 +19,11 @@ type natsBroker struct {
// indicate if we're connected
connected bool
addrs []string
conn *nats.Conn
opts broker.Options
nopts nats.Options
init bool
addrs []string
conn *nats.Conn
opts broker.Options
nopts nats.Options
// should we drain the connection
drain bool
@@ -156,6 +156,23 @@ func (n *natsBroker) Disconnect(ctx context.Context) error {
}
func (n *natsBroker) Init(opts ...broker.Option) error {
if len(opts) == 0 && n.init {
return nil
}
if err := n.opts.Register.Init(); err != nil {
return err
}
if err := n.opts.Tracer.Init(); err != nil {
return err
}
if err := n.opts.Logger.Init(); err != nil {
return err
}
if err := n.opts.Meter.Init(); err != nil {
return err
}
n.setOption(opts...)
if n.opts.Codec == nil {
return fmt.Errorf("codec is nil")