Sha256: f2e6596b0d39f80ae5b73936033eaec74e051956cb7e68900ff1bac8b3cecc1d

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

#
# HornetQ Consumer:
#          Read a single message from the queue
#

# Allow examples to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'

require 'rubygems'
require 'hornetq'

# Using Connect.start since a session must be started in order to consume messages
HornetQ::Client::Connection.start_session(
  :connection => {:uri => 'hornetq://stage1'} ,
  :session => { :username => 'clarity', :password => 'clarityrul3s'}) do |session|
  
  # Create a non-durable TestQueue to receive messages sent to the TestAddress
  session.create_queue_ignore_exists('jms.queue.SampleQueue', 'jms.queue.SampleQueue', false)
  
  # Consume All messages from the queue and gather statistics
  stats = session.consume(:queue_name => 'jms.queue.SampleQueue', :timeout=> 0, :statistics=>true) do |message|
    puts "Body Size:#{message.body_size}"
    p message
    puts "=================================="
    message.acknowledge
  end
  puts "Received #{stats[:count]} messages in #{stats[:duration]} seconds at #{stats[:messages_per_second]} messages per second"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-hornetq-0.3.2 examples/producer-consumer/consume_all.rb