From 0c03bf064b533180e0cc083da7f6ef3e50c08d5b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sun, 19 Jan 2020 13:45:28 +0000 Subject: [PATCH] only connect broker if there are subscribers --- server/grpc/grpc.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index b039c021..d8a1cb89 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -752,16 +752,19 @@ func (g *grpcServer) Start() error { g.opts.Address = ts.Addr().String() g.Unlock() - // connect to the broker - if err := config.Broker.Connect(); err != nil { - return err + // only connect if we're subscribed + if len(g.subscribers) > 0 { + // connect to the broker + if err := config.Broker.Connect(); err != nil { + return err + } + + baddr := config.Broker.Address() + bname := config.Broker.String() + + log.Logf("Broker [%s] Connected to %s", bname, baddr) } - baddr := config.Broker.Address() - bname := config.Broker.String() - - log.Logf("Broker [%s] Connected to %s", bname, baddr) - // announce self to the world if err := g.Register(); err != nil { log.Log("Server register error: ", err)