Sha256: 7bb1b9b0381b1bef8056ef2318280fca8b1628a2027cc6fae9a6044b93dcaf77
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
# # HornetQ Consumer: # Multi-threaded Consumer # # Allow examples to be run in-place without requiring a gem install $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib' require 'rubygems' require 'yaml' require 'hornetq' # Arguments: 'number of threads' 'timeout' $thread_count = (ARGV[0] || 3).to_i $timeout = (ARGV[1] || 1000).to_i config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development'] def worker(id, session) begin consumer = session.create_consumer('jms.queue.ExampleQueue') session.start count = 0 start_time = Time.now while message = consumer.receive($timeout) count = count + 1 message.acknowledge #puts "==================================" #text = message.body #p text #p message puts "Durable" if message.durable print "#{id}." end duration = Time.now - start_time - $timeout/1000 puts "\nReceived #{count} messages in #{duration} seconds at #{count/duration} messages per second" rescue Exception => exc puts "Thread #{id} Terminating" p exc ensure session.close end end # Create a HornetQ session HornetQClient::Factory.create_factory(config[:connector]) do |factory| threads = [] $thread_count.times do |i| session = factory.create_session(config[:session]) threads << Thread.new { worker(i, session) } end threads.each {|t| t.join} end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jruby-hornetq-0.2.0.alpha | examples/multi_consumer.rb |