Permalink
Browse files

Allow raw mode from master

  • Loading branch information...
1 parent 55d9d16 commit 312ad0053327a866346ca000679324cd285caf79 @derekcollison derekcollison committed Mar 11, 2013
Showing with 39 additions and 13 deletions.
  1. +14 −5 bin/nats-queue
  2. +12 −3 bin/nats-request
  3. +13 −5 bin/nats-sub
View
@@ -7,14 +7,14 @@ require 'nats/client'
['TERM', 'INT'].each { |s| trap(s) { puts; exit! } }
def usage
- puts "Usage: nats-queue <subject> <queue name> [-s server] [-t]"; exit
+ puts "Usage: nats-queue <subject> <queue name> [-s server] [-t] [-r]"; exit
end
args = ARGV.dup
opts_parser = OptionParser.new do |opts|
opts.on('-s SERVER') { |server| $nats_server = server }
- opts.on('-t') { $show_time = true }
-
+ opts.on('-t','--time') { $show_time = true }
+ opts.on('-r','--raw') { $show_raw = true }
end
args = opts_parser.parse!(args)
@@ -30,11 +30,20 @@ def header
"#{time_prefix}[\##{$i+=1}]"
end
+def decorate sub, msg
+ if $show_raw
+ msg
+ else
+ "#{header} Received on [#{sub}] : '#{msg}'"
+ end
+end
+
+
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
NATS.start(:uri => $nats_server, :autostart => true) do
- puts "Listening on [#{subject}], queue group [#{queue_group}]"
+ puts "Listening on [#{subject}], queue group [#{queue_group}]" unless $show_raw
NATS.subscribe(subject, :queue => queue_group) { |msg, _, sub|
- puts "#{header} Received on [#{sub}] : '#{msg}'"
+ puts decorate(sub, msg)
}
end
View
@@ -7,13 +7,14 @@ require 'nats/client'
['TERM', 'INT'].each { |s| trap(s) { puts; exit! } }
def usage
- puts "Usage: nats-request <subject> <msg> [-s server] [-t] [-n responses]"; exit
+ puts "Usage: nats-request <subject> <msg> [-s server] [-t] [-r] [-n responses]"; exit
end
args = ARGV.dup
opts_parser = OptionParser.new do |opts|
opts.on('-s SERVER') { |server| $nats_server = server }
- opts.on('-t') { $show_time = true }
+ opts.on('-t','--time') { $show_time = true }
+ opts.on('-r','--raw') { $show_raw = true }
opts.on('-n RESPONSES') { |responses| $responses = Integer(responses) if Integer(responses) > 0 }
end
args = opts_parser.parse!(args)
@@ -31,11 +32,19 @@ def header
"#{time_prefix}[\##{$i+=1}]"
end
+def decorate msg
+ if $show_raw
+ msg
+ else
+ "#{header} Replied with : '#{msg}'"
+ end
+end
+
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
NATS.start(:uri => $nats_server, :autostart => true) do
NATS.request(subject, msg) { |(msg, reply)|
- puts "#{header} Replied with : '#{msg}'"
+ puts decorate(msg)
exit! if $responses && ($responses-=1) < 1
}
end
View
@@ -7,14 +7,14 @@ require 'nats/client'
['TERM', 'INT'].each { |s| trap(s) { puts; exit! } }
def usage
- puts "Usage: nats-sub <subject> [-s server] [-t]"; exit
+ puts "Usage: nats-sub <subject> [-s server] [-t] [-r]"; exit
end
args = ARGV.dup
opts_parser = OptionParser.new do |opts|
opts.on('-s SERVER') { |server| $nats_server = server }
- opts.on('-t') { $show_time = true }
-
+ opts.on('-t','--time') { $show_time = true }
+ opts.on('-r','--raw') { $show_raw = true }
end
args = opts_parser.parse!(args)
@@ -30,9 +30,17 @@ def header
"#{time_prefix}[\##{$i+=1}]"
end
+def decorate sub, msg
+ if $show_raw
+ msg
+ else
+ "#{header} Received on [#{sub}] : '#{msg}'"
+ end
+end
+
NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
NATS.start(:uri => $nats_server, :autostart => true) do
- puts "Listening on [#{subject}]"
- NATS.subscribe(subject) { |msg, _, sub| puts "#{header} Received on [#{sub}] : '#{msg}'" }
+ puts "Listening on [#{subject}]" unless $show_raw
+ NATS.subscribe(subject) { |msg, _, sub| puts decorate(sub, msg) }
end

0 comments on commit 312ad00

Please sign in to comment.