Skip to content

Commit

Permalink
Several fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
Waldemar Quevedo committed Oct 24, 2016
1 parent 4ac4a2a commit 63bb718
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 188 deletions.
31 changes: 22 additions & 9 deletions examples/clustered.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'nats/io/client'

$stdout.sync = true
nats = NATS::IO::Client.new

nats.on_reconnect do
Expand All @@ -15,22 +16,34 @@
end

cluster_opts = {
servers: ["nats://127.0.0.1:4222", "nats://127.0.0.1:4223"],
servers: ["nats://127.0.0.1:4222", "nats://127.0.0.1:4223","nats://127.0.0.1:4224"],
dont_randomize_servers: true,
reconnect_time_wait: 0.5,
max_reconnect_attempts: 2
reconnect_time_wait: 1,
max_reconnect_attempts: 5
}

nats.connect(cluster_opts)
puts "Connected to #{nats.connected_server}"

nats.subscribe("hello") do |data|
puts "#{Time.now} - Received: #{data}"
msgs_sent = 0
msgs_received = 0
bytes_sent = 0
bytes_received = 0

nats.subscribe("hello") {|data| msgs_received += 1; bytes_received += data.size }

Thread.new do
loop do
puts "#{Time.now} #{Thread.list.count} - [Sent/Received] #{msgs_sent}/#{msgs_received} msgs (#{msgs_sent - msgs_received}) | [Received] #{bytes_sent}/#{bytes_received} B (#{bytes_sent - bytes_received})"
p Thread.list
sleep 1
end
end

n = 0
loop do
n += 1
nats.publish("hello", "world.#{n}")
sleep 0.1
payload = "world.#{msgs_sent}"
nats.publish("hello", payload)
msgs_sent += 1
bytes_sent += payload.size
sleep 0.00001
end
Loading

0 comments on commit 63bb718

Please sign in to comment.