func NewNsqdServer(opts *nsqd.Options) (*nsqd.NSQD, *NsqdServer) { ip := opts.DecideBroadcast() nsqdInstance := nsqd.New(opts) s := &NsqdServer{} ctx := &context{} ctx.nsqd = nsqdInstance _, port, _ := net.SplitHostPort(opts.TCPAddress) rpcport := opts.RPCPort if rpcport != "" { ip = opts.BroadcastAddress consistence.SetCoordLogger(opts.Logger, opts.LogLevel) coord := consistence.NewNsqdCoordinator(opts.ClusterID, ip, port, rpcport, strconv.FormatInt(opts.ID, 10), opts.DataPath, nsqdInstance) l := consistence.NewNsqdEtcdMgr(opts.ClusterLeadershipAddresses) coord.SetLeadershipMgr(l) ctx.nsqdCoord = coord } else { nsqd.NsqLogger().LogWarningf("Start without nsqd coordinator enabled") ctx.nsqdCoord = nil } s.ctx = ctx s.exitChan = make(chan int) tlsConfig, err := buildTLSConfig(opts) if err != nil { nsqd.NsqLogger().LogErrorf("FATAL: failed to build TLS config - %s", err) os.Exit(1) } if tlsConfig == nil && opts.TLSRequired != TLSNotRequired { nsqd.NsqLogger().LogErrorf("FATAL: cannot require TLS client connections without TLS key and cert") os.Exit(1) } s.ctx.tlsConfig = tlsConfig s.ctx.nsqd.SetPubLoop(s.ctx.internalPubLoop) nsqd.NsqLogger().Logf(version.String("nsqd")) nsqd.NsqLogger().Logf("ID: %d", opts.ID) return nsqdInstance, s }