make the broker/transport listen on new addr when stop/started with addr :0
This commit is contained in:
		| @@ -326,10 +326,16 @@ func (h *httpBroker) Connect() error { | ||||
| 	} | ||||
|  | ||||
| 	log.Logf("Broker Listening on %s", l.Addr().String()) | ||||
| 	addr := h.address | ||||
| 	h.address = l.Addr().String() | ||||
|  | ||||
| 	go http.Serve(l, h.mux) | ||||
| 	go h.run(l) | ||||
| 	go func() { | ||||
| 		h.run(l) | ||||
| 		h.Lock() | ||||
| 		h.address = addr | ||||
| 		h.Unlock() | ||||
| 	}() | ||||
|  | ||||
| 	// get registry | ||||
| 	reg, ok := h.opts.Context.Value(registryKey).(registry.Registry) | ||||
|   | ||||
| @@ -386,6 +386,8 @@ func (s *rpcServer) Start() error { | ||||
|  | ||||
| 	log.Logf("Listening on %s", ts.Addr()) | ||||
| 	s.Lock() | ||||
| 	// swap address | ||||
| 	addr := s.opts.Address | ||||
| 	s.opts.Address = ts.Addr() | ||||
| 	s.Unlock() | ||||
|  | ||||
| @@ -405,6 +407,11 @@ func (s *rpcServer) Start() error { | ||||
|  | ||||
| 		// disconnect the broker | ||||
| 		config.Broker.Disconnect() | ||||
|  | ||||
| 		s.Lock() | ||||
| 		// swap back address | ||||
| 		s.opts.Address = addr | ||||
| 		s.Unlock() | ||||
| 	}() | ||||
|  | ||||
| 	// TODO: subscribe to cruft | ||||
|   | ||||
		Reference in New Issue
	
	Block a user