Skip to content

Commit

Permalink
Merge pull request #91 from devin-c/dynamic_discovery
Browse files Browse the repository at this point in the history
Dynamic discovery for zmq server and client
  • Loading branch information
localshred committed Jun 13, 2013
2 parents 9b6a808 + 05fd332 commit 6297dc6
Show file tree
Hide file tree
Showing 37 changed files with 1,646 additions and 559 deletions.
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ any other filter calls which would run afterwards, as well as canceling
invocation of the service method. Note: You must actually return false,
not just a "falsey" value such as nil.

__After Filters__ – There is no request shortcutting since the after
filter runs after the request. Duh.
__After Filters__ – No request shortcutting.

#### Filter options

Expand Down Expand Up @@ -415,6 +414,44 @@ Many different options can be passed to the `.client` call above
(such as `:timeout => 600`). See the `lib/protobuf/rpc/client.rb`
and `lib/protobuf/rpc/service.rb` files for more documentation.

### Dynamic Discovery (ZMQ Only)
It is possible to setup the RPC server and client in a way that
allows servers to be dynamically discovered by the client.

#### In the client
```ruby
ServiceDirectory.start do |config|
config.port = 53000
end

# If your server also runs this code, 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
```

#### Starting the server
```
$ 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 {Protobuf::ServiceDirectory} for more details.

## 3. RPC Interop

The main reason I wrote this gem was to provide a ruby implementation
Expand Down
32 changes: 16 additions & 16 deletions lib/protobuf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Protobuf
# Default is Socket as it has no external dependencies.
DEFAULT_CONNECTOR = :socket

module_function
module_function

# Client Host
#
Expand Down Expand Up @@ -53,14 +53,14 @@ def self.connector_type=(type)
# the Garbage Collector when handling an rpc request.
# Once the request is completed, the GC is enabled again.
# This optomization provides a huge boost in speed to rpc requests.
def self.gc_pause_server_request?
return @_gc_pause_server_request unless @_gc_pause_server_request.nil?
gc_pause_server_request = false
end
def self.gc_pause_server_request?
return @_gc_pause_server_request unless @_gc_pause_server_request.nil?
gc_pause_server_request = false
end

def self.gc_pause_server_request=(value)
@_gc_pause_server_request = !!value
end
def self.gc_pause_server_request=(value)
@_gc_pause_server_request = !!value
end

# Print Deprecation Warnings
#
Expand All @@ -72,14 +72,14 @@ def self.gc_pause_server_request=(value)
# ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value.
#
# The rpc_server option will override the ENV setting.
def self.print_deprecation_warnings?
return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil?
print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true
end

def self.print_deprecation_warnings=(value)
@_print_deprecation_warnings = !!value
end
def self.print_deprecation_warnings?
return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil?
print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true
end

def self.print_deprecation_warnings=(value)
@_print_deprecation_warnings = !!value
end

end

Expand Down
Loading

0 comments on commit 6297dc6

Please sign in to comment.