环境搭建:
nats源码学习记录--程序启动,使用对应的seed.conf中的配置。
添加新的ROUTER,gnatsd.exe -p 5222 -cluster nats://localhost:5248 -routes nats://0.0.0.0:4248 -D ,gnatsd.exe 为gnatsd程序。
服务开启的时候,会搜索本集群 router对应的url,对应于上面信息的nats://0.0.0.0:4248;找到后,就立即启动链接的建立。
func (s *Server) StartRouting(clientListenReady chan struct{}) { defer s.grWG.Done() // Wait for the client listen port to be opened, and // the possible ephemeral port to be selected. <-clientListenReady // Spin up the accept loop ch := make(chan struct{}) //本地监听开启,方便本集群的其他ROUTER发链接请求 go s.routeAcceptLoop(ch) <-ch // Solicit Routes if needed. //和本集群 内的其他router建立连接 s.solicitRoutes(s.getOpts().Routes) }
func (s *Server) solicitRoutes(routes []*url.URL) { for _, r := range routes { route := r fmt.Println("sol