stan: fix error when multiple times calling Connect method

dont overwrite passed options to avoid error:
impossible to use custom ConnectionLostCB and ConnectRetry(true)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-06-19 03:09:12 +03:00
parent 44de02e879
commit 09f946bd6b

10
stan.go
View File

@ -218,10 +218,6 @@ func (n *stanBroker) Connect() error {
return errors.New("impossible to use custom ConnectionLostCB and ConnectRetry(true)") return errors.New("impossible to use custom ConnectionLostCB and ConnectRetry(true)")
} }
if n.connectRetry {
n.sopts.ConnectionLostCB = n.reconnectCB
}
nopts := []stan.Option{ nopts := []stan.Option{
stan.NatsURL(n.sopts.NatsURL), stan.NatsURL(n.sopts.NatsURL),
stan.NatsConn(n.sopts.NatsConn), stan.NatsConn(n.sopts.NatsConn),
@ -229,8 +225,12 @@ func (n *stanBroker) Connect() error {
stan.PubAckWait(n.sopts.AckTimeout), stan.PubAckWait(n.sopts.AckTimeout),
stan.MaxPubAcksInflight(n.sopts.MaxPubAcksInflight), stan.MaxPubAcksInflight(n.sopts.MaxPubAcksInflight),
stan.Pings(n.sopts.PingInterval, n.sopts.PingMaxOut), stan.Pings(n.sopts.PingInterval, n.sopts.PingMaxOut),
stan.SetConnectionLostHandler(n.sopts.ConnectionLostCB),
} }
if n.connectRetry {
nopts = append(nopts, stan.SetConnectionLostHandler(n.reconnectCB))
}
nopts = append(nopts, stan.NatsURL(strings.Join(n.addrs, ","))) nopts = append(nopts, stan.NatsURL(strings.Join(n.addrs, ",")))
n.nopts = nopts n.nopts = nopts