module RubySkynet

Autodetect if Zookeeper gem is loaded, otherwise look for Doozer

RubySkynet Client

Supports

RPC calls to Skynet
Skynet Service autodiscovery

RubySkynet Client Connection

Handles connecting to Skynet Servers as a host:port pair

RubySkynet Sevices Registry

Based on the Skynet Services Registry, obtains and keeps up to date a list of all services and which servers they are available on.

RubySkynet Server

Hosts one or more Skynet Services

RubySkynet Service

Supports

Hosting Skynet Services
Skynet Service registration

RubySkynet Sevices Registry

Loads a list of all services and which servers they are available on from a static YAML file

Format of the YAML file

key: [String] "<name>/<version>/<region>"
value: [Array<String>] 'host:port', 'host:port'

CachedRegistry

Store information in ZooKeeper and subscribe to future changes and keep a local copy of the information in ZooKeeper

Notifies registered subscribers when information has changed

All paths specified are relative to the root_path. As such the root key is never returned, nor is it required when a key is supplied as input. For example, with a root_path of /foo/bar, any paths passed in will leave out the root_path: host/name

Keeps a local copy in memory of all descendant values of the supplied root_path Supports high-frequency calls to retrieve registry data The in-memory cache will be kept in synch with any changes on the server

RubySkynet Sevices Registry

Based on the Skynet Services Registry, obtains and keeps up to date a list of all services and which servers they are available on.

Constants

CachedRegistry
Registry
ServiceRegistry

Shortcuts to loaded Registry classes

VERSION

Public Class Methods

configure!(filename=nil, environment=nil) click to toggle source

Load the Configuration information from a YAML file

filename:
  Name of file to read.
      Mandatory for non-Rails apps
      Default: Rails.root/config/ruby_skynet.yml
environment:
  Which environment config to load. Usually: production, development, etc.
  Default: Rails.env
# File lib/ruby_skynet/ruby_skynet.rb, line 81
def self.configure!(filename=nil, environment=nil)
  config_file = filename.nil? ? Rails.root.join('config', 'ruby_skynet.yml') : Pathname.new(filename)
  raise "ruby_skynet config not found. Create a config file at: config/ruby_skynet.yml" unless config_file.file?

  config = YAML.load(ERB.new(File.new(config_file).read).result)[environment || Rails.env]
  raise("Environment #{Rails.env} not defined in config/ruby_skynet.yml") unless config

  @@config = config.dup

  RubySkynet.region           = config.delete(:region)           || 'Development'
  RubySkynet.services_path    = config.delete(:services_path)    || 'app/services'
  RubySkynet.server_port      = config.delete(:server_port)      || 2000
  RubySkynet.local_ip_address = config.delete(:local_ip_address) || Common::local_ip_address

  # Extract the registry configuration element
  RubySkynet.service_registry = ServiceRegistry.new(
    :registry => config.delete(:registry)
  )

  config.each_pair {|k,v| warn "Ignoring unknown RubySkynet config option #{k} => #{v}"}
end
configured?() click to toggle source

Returns [Boolean] whether the RubySkynet.configure! method has already been called

# File lib/ruby_skynet/ruby_skynet.rb, line 104
def self.configured?
  !@@config.nil?
end
local_ip_address() click to toggle source

The ip address at which this server instance can be reached by remote Skynet clients Note: Must be an IP address, not the hostname

# File lib/ruby_skynet/ruby_skynet.rb, line 41
def self.local_ip_address
  @@local_ip_address ||= Common::local_ip_address
end
local_ip_address=(local_ip_address) click to toggle source
# File lib/ruby_skynet/ruby_skynet.rb, line 45
def self.local_ip_address=(local_ip_address)
  @@local_ip_address = local_ip_address
end
region() click to toggle source

Returns the default region for all Ruby Skynet Clients and Services

# File lib/ruby_skynet/ruby_skynet.rb, line 8
def self.region
  @@region ||= 'Development'
end
region=(region) click to toggle source

Sets the default region to use for Skynet Clients and Services

# File lib/ruby_skynet/ruby_skynet.rb, line 13
def self.region=(region)
  @@region = region
end
registry_config() click to toggle source

Returns the current Registry Config information

By default it connects to a local ZooKeeper instance Use .configure! to supply a configuration file with any other settings

# File lib/ruby_skynet/ruby_skynet.rb, line 62
def self.registry_config
  @@config.dup if @@config
end
server_port() click to toggle source

Returns the starting port for the server to listen on If this port is in use the next available port will be used upto 999 above the server_port value

# File lib/ruby_skynet/ruby_skynet.rb, line 30
def self.server_port
  @@server_port ||= 2000
end
server_port=(server_port) click to toggle source
# File lib/ruby_skynet/ruby_skynet.rb, line 34
def self.server_port=(server_port)
  @@server_port = server_port
end
service_registry=(service_registry) click to toggle source

Set the services registry

It is recommended to call RubySkynet.configure! rather than calling this
method directly
# File lib/ruby_skynet/ruby_skynet.rb, line 69
def self.service_registry=(service_registry)
  @@service_registry = service_registry
end
services_path() click to toggle source

Returns the service_path where services are located

# File lib/ruby_skynet/ruby_skynet.rb, line 18
def self.services_path
  @@services_path ||= 'app/services'
end
services_path=(services_path) click to toggle source

Sets the service_path where services are located

# File lib/ruby_skynet/ruby_skynet.rb, line 23
def self.services_path=(services_path)
  @@services_path = services_path
end