Created
August 31, 2015 14:39
-
-
Save film42/6d674d5b0d97c5c07d3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "nats/client" | |
def get_request | |
start = nil | |
NATS.start(:servers => ['nats://198.199.103.139:4222']) do | |
start = Time.now | |
NATS.subscribe('demo') do |msg, reply| | |
NATS.publish(reply, "Polo!") | |
end | |
NATS.request('demo', "Marcko...") do |response| | |
duration = Time.now - start | |
puts "Duration: #{duration * 1000} ms" | |
NATS.stop | |
end | |
end | |
end | |
Thread.new do | |
message = '' | |
while ZMQ::Util.resultcode_ok?(rc) | |
rc = rep_sock.recv_string(message) | |
puts "Received request '#{message}'" | |
rc = rep_sock.send_string('Polo!') | |
end | |
end | |
require 'ffi-rzmq' | |
ctx = ZMQ::Context.create(1) | |
req_sock = ctx.socket(ZMQ::REQ) | |
rc = req_sock.connect('tcp://198.199.103.139:5000') | |
require 'benchmark' | |
def bench(req_sock) | |
Benchmark.measure do | |
rc = req_sock.send_string('Marco...') | |
rep = '' | |
rc = req_sock.recv_string(rep) | |
rep | |
end | |
end | |
bench(req_sock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment