make the broker/transport listen on new addr when stop/started with addr :0

This commit is contained in:
Asim Aslam 2018-05-25 15:19:25 +01:00
parent 6444b7e24c
commit c666558f8c
2 changed files with 14 additions and 1 deletions

View File

@ -326,10 +326,16 @@ func (h *httpBroker) Connect() error {
} }
log.Logf("Broker Listening on %s", l.Addr().String()) log.Logf("Broker Listening on %s", l.Addr().String())
addr := h.address
h.address = l.Addr().String() h.address = l.Addr().String()
go http.Serve(l, h.mux) go http.Serve(l, h.mux)
go h.run(l) go func() {
h.run(l)
h.Lock()
h.address = addr
h.Unlock()
}()
// get registry // get registry
reg, ok := h.opts.Context.Value(registryKey).(registry.Registry) reg, ok := h.opts.Context.Value(registryKey).(registry.Registry)

View File

@ -386,6 +386,8 @@ func (s *rpcServer) Start() error {
log.Logf("Listening on %s", ts.Addr()) log.Logf("Listening on %s", ts.Addr())
s.Lock() s.Lock()
// swap address
addr := s.opts.Address
s.opts.Address = ts.Addr() s.opts.Address = ts.Addr()
s.Unlock() s.Unlock()
@ -405,6 +407,11 @@ func (s *rpcServer) Start() error {
// disconnect the broker // disconnect the broker
config.Broker.Disconnect() config.Broker.Disconnect()
s.Lock()
// swap back address
s.opts.Address = addr
s.Unlock()
}() }()
// TODO: subscribe to cruft // TODO: subscribe to cruft