Add connection lost handler for NATS-streaming (#1125)

This commit is contained in:
Ta-Ching Chen
2019-03-19 21:13:49 +08:00
committed by GitHub
parent 3a8b9ccd80
commit cdcc6fb3ab
+10 -1
View File
@@ -47,7 +47,16 @@ type (
)
func makeNatsMessageQueue(logger *zap.Logger, routerUrl string, mqCfg MessageQueueConfig) (MessageQueue, error) {
conn, err := ns.Connect(natsClusterID, natsClientID, ns.NatsURL(mqCfg.Url))
conn, err := ns.Connect(natsClusterID, natsClientID, ns.NatsURL(mqCfg.Url),
ns.SetConnectionLostHandler(func(conn ns.Conn, reason error) {
// TODO: Better way to handle connection lost problem.
// Currently, MessageQueue has no such interface to expose the status of underlying
// messaging service, hence MessageQueueTriggerManager has no way to detect and handle
// such situation properly. It takes some time to redesign interface of MessageQueue.
// For now, we simply fatal here.
logger.Fatal("Connection lost", zap.Error(reason))
}),
)
if err != nil {
return nil, err
}