Sha256: 6afd2b9aac93dbd4e4c2d08516e729e91b9a0f6182e01494f4dffec2cbe50366
Contents?: true
Size: 1.4 KB
Versions: 4
Compression:
Stored size: 1.4 KB
Contents
# Allow examples to be run in-place without requiring a gem install $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib' require 'rubygems' require 'erb' require 'modern_times' require 'yaml' require 'reverse_echo_worker' if ARGV.size < 1 $stderr.puts "Usage: {$0} <reverse-echo-string> [<timeout>] [<sleep-time>] [<simultaneous-count>]" exit 1 end $echo_string = ARGV[0] $timeout = (ARGV[1] || 4).to_f $sleep_time = (ARGV[2] || 2).to_i $sim_count = (ARGV[3] || 1).to_i config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), '..', 'jms.yml'))).result(binding)) ModernTimes::JMS::Connection.init(config) $publisher = ModernTimes::JMS::Publisher.new(:queue_name => ReverseEchoWorker.default_name, :response =>true, :marshal => :string) def make_request(ident='') puts "#{ident}Making request at #{Time.now.to_f}" handle = $publisher.publish("#{ident}#{$echo_string}") # Here's where we'd go off and do other work sleep $sleep_time puts "#{ident}Finished sleeping at #{Time.now.to_f}" response = handle.read_response($timeout) puts "#{ident}Received at #{Time.now.to_f}: #{response}" rescue Exception => e puts "#{ident}Exception: #{e.message}\n\t#{e.backtrace.join("\n\t")}" end if $sim_count == 1 make_request else threads = [] (1..$sim_count).each do |i| threads << Thread.new(i) do |i| make_request("Thread ##{i}: ") end end threads.each {|t| t.join} end
Version data entries
4 entries across 4 versions & 1 rubygems