Sha256: 08b4c952969cdccec2377f18fe904b8fcbc6d1316bb2bdb57d297aedd0aa06b1

Contents?: true

Size: 950 Bytes

Versions: 2

Compression:

Stored size: 950 Bytes

Contents

#!/usr/bin/env jruby
#
# HornetQ Consumer:
#          Write messages to the queue
#

require 'rubygems'
require 'yaml'
require 'hornetq'

timeout = (ARGV[0] || 3000).to_i

config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')
constants = config['constants']

# Create a HornetQ session
HornetQ::Client::Factory.session(config['client']) do |session|
  consumer = session.create_consumer(constants[:queue])
  session.start

  i = 0
  start_time = Time.now
  while message = consumer.receive(timeout)
    i += 1
    message.acknowledge
    expected_message = "Message ##{i}"
    if message.body != expected_message
      puts "Unexpected message: #{message.body} Expected: #{expected_message}"
      i = $1.to_i if message.body =~ /Message #(\d+)/
    end
    puts "#{i}\n" if i%1000 == 0
  end
  duration = Time.now - start_time - timeout/1000
  puts "Received #{i} messages in #{duration} seconds at #{i/duration} messages per second"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jruby-hornetq-0.2.5.alpha examples/advanced/transaction-failover/consumer.rb
jruby-hornetq-0.2.3.alpha examples/advanced/transaction-failover/consumer.rb