Add example of ZeroMQ
This commit is contained in:
parent
e02ab48e51
commit
3528a28127
4 changed files with 254 additions and 0 deletions
35
lib/package.rb
Normal file
35
lib/package.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
module Package
|
||||
require_relative "package/daemon"
|
||||
require_relative "package/client"
|
||||
|
||||
ENDPOINT = "ipc:///tmp/zmq-rpc-demo"
|
||||
|
||||
def self.make(name, scope)
|
||||
puts "making package named: #{name} at #{scope}"
|
||||
|
||||
c = RpcClient.new(ENDPOINT, timeout_ms: 2000)
|
||||
begin
|
||||
puts "echo => #{c.call("echo", {"hello"=>"world"})}"
|
||||
puts "add => #{c.call("add", [1, 2, 3.5])}"
|
||||
puts "time => #{c.call("time")}"
|
||||
rescue ::Timeout::Error
|
||||
warn "RPC timeout: is the daemon running and bound to #{ENDPOINT}?"
|
||||
warn "Start it with: ruby daemon.rb (or your systemd service)"
|
||||
rescue => e
|
||||
warn "RPC error: #{e.class}: #{e.message}"
|
||||
ensure
|
||||
c.close
|
||||
end
|
||||
end
|
||||
|
||||
def self.install(name, scope)
|
||||
puts "making package named: #{name} at #{scope}"
|
||||
end
|
||||
|
||||
# gem install ffi-rzmq
|
||||
def self.daemon
|
||||
start_daemon(ENDPOINT)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue