func (router *Router) Run() { var err error go func() { for { err = router.mbusClient.Connect() if err == nil { break } log.Errorf("Could not connect to NATS: ", err.Error()) time.Sleep(500 * time.Millisecond) } }() router.RegisterComponent() // Kickstart sending start messages router.SendStartMessage() // Subscribe register/unregister router router.SubscribeRegister() router.SubscribeUnregister() // Schedule flushing active app's app_id router.ScheduleFlushApps() // Wait for one start message send interval, such that the router's registry // can be populated before serving requests. if router.config.PublishStartMessageInterval != 0 { log.Infof("Waiting %s before listening...", router.config.PublishStartMessageInterval) time.Sleep(router.config.PublishStartMessageInterval) } listen, err := net.Listen("tcp", fmt.Sprintf(":%d", router.config.Port)) if err != nil { log.Fatalf("net.Listen: %s", err) } util.WritePidFile(router.config.Pidfile) log.Infof("Listening on %s", listen.Addr()) server := proxy.Server{Handler: router.proxy} err = server.Serve(listen) if err != nil { log.Fatalf("proxy.Serve: %s", err) } }
func (r *Router) Run() { var err error // Subscribe register/unregister router r.SubscribeRegister() r.SubscribeUnregister() r.SubscribeStatus() // Kickstart sending start messages r.SendStartMessage() // Schedule flushing active app's app_id r.ScheduleFlushApps() fmt.Printf("available cpu = %d \n", runtime.NumCPU()) //runtime.GOMAXPROCS(2) // Wait for one start message send interval, such that the router's registry // can be populated before serving requests. if r.config.PublishStartMessageInterval != 0 { log.Infof("Waiting %s before listening...", r.config.PublishStartMessageInterval) time.Sleep(r.config.PublishStartMessageInterval) } fmt.Printf(":%d \n", r.config.Port) l, err := net.Listen("tcp", fmt.Sprintf(":%d", r.config.Port)) if err != nil { log.Fatalf("net.Listen: %s", err) } util.WritePidFile(r.config.Pidfile) log.Infof("Listening on %s", l.Addr()) s := proxy.Server{Handler: r.proxy} // 这里的proxy? Server?? err = s.Serve(l) //这里估计也是一个死循环? if err != nil { log.Fatalf("proxy.Serve: %s", err) } }
func (r *Router) Run() { var err error // Subscribe register/unregister router r.SubscribeRegister() r.SubscribeUnregister() // Kickstart sending start messages r.SendStartMessage() // Schedule flushing active app's app_id r.ScheduleFlushApps() infoHandler := InfoHandler{addr: r.config.InfoHostPort, m: r.registry} go infoHandler.Run() // Wait for one start message send interval, such that the router's registry // can be populated before serving requests. if r.config.PublishStartMessageInterval != 0 { log.Infof("Waiting %s before listening...", r.config.PublishStartMessageInterval) time.Sleep(r.config.PublishStartMessageInterval) } l, err := net.Listen("tcp", fmt.Sprintf(":%d", r.config.Port)) if err != nil { log.Fatalf("net.Listen: %s", err) } util.WritePidFile(r.config.Pidfile) log.Infof("Listening on %s", l.Addr()) s := proxy.Server{Handler: r.proxy} err = s.Serve(l) if err != nil { log.Fatalf("proxy.Serve: %s", err) } }