Skip to content

Commit

Permalink
make the broker/transport listen on new addr when stop/started with a…
Browse files Browse the repository at this point in the history
…ddr :0
  • Loading branch information
Asim Aslam committed May 25, 2018
1 parent 6444b7e commit c666558
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion broker/http_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions server/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down

0 comments on commit c666558

Please sign in to comment.