Permalink
Browse files

new example to show off nats-top output

  • Loading branch information...
derekcollison committed Dec 22, 2011
1 parent 64142a7 commit 0560a30b3cad4639914c652801fcf982d114eace
Showing with 38 additions and 0 deletions.
  1. +38 −0 examples/busy_body.rb
View
@@ -0,0 +1,38 @@
+require 'rubygems'
+require 'nats/client'
+
+# This is an example to show off nats-top. Run busy_body on a monitor enabled
+# server and exec nats-top.
+
+['TERM', 'INT'].each { |sig| trap(sig) { exit! } }
+
+NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
+
+def create_subscribers(sub='foo.bar', num_subs=10, num_connections=20)
+ (1..num_connections).each do
+ NATS.connect do |nc|
+ (1..num_subs).each { nc.subscribe(sub) }
+ end
+ end
+end
+
+def create_publishers(sub='foo.bar', body='Hello World!', num_connections=20, num_sends=100)
+ (1..num_connections).each do
+ NATS.connect do |nc|
+ (1..num_sends).each { nc.publish(sub, body) }
+ end
+ end
+end
+
+def timed_publish(sub='foo.bar', body='Hello World!', delay=1, burst=500)
+ EM.add_periodic_timer(1) do
+ b = (burst * rand).to_i
+ (1..b).each { NATS.publish(sub, body) }
+ end
+end
+
+NATS.start {
+ create_subscribers
+ create_publishers
+ timed_publish
+}

0 comments on commit 0560a30

Please sign in to comment.