Skip to content
BJ Neilsen edited this page Sep 13, 2013 · 1 revision

It is possible to setup the RPC server and client in a way that allows servers/services to be dynamically discovered by client processes.

Client Configuration

ServiceDirectory.start do |config|
  config.port = 53000
end

# If your server also runs this code (say from an initializer),
# it will default to the given port when sending
# beacons and have its own service directory.
# You can prevent this code from running on the server if needed:
unless defined?(::Protobuf::CLI)
  ServiceDirectory.start do |config|
    config.port = 53000
  end
end

Server Configuration with Dynamic Discovery enabled

$ rpc_server --broadcast-beacons --beacon-port 53000 ...

The client will listen on the specified port for beacons broadcast by servers. Each beacon includes a list of services provided by the broadcasting server. The client randomly selects a server for the desired service each time a request is made.

CAUTION: When running multiple environments on a single network, e.g., qa and staging, be sure that each environment is setup with a unique beacon port; otherwise, clients in one environment will make requests to servers in the other environment.

Check out the source for Protobuf::Rpc::ServiceDirectory for more details.

Clone this wiki locally