Sha256: 4e3f8b299c132ec3a28d614da54bdafb892c3ae1b6ae96049c25f3abc80dd216

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 Bytes

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('hornetq://localhost') do |session|

  # Create the non-durable TestQueue to receive messages sent to the TestAddress
  session.create_queue_ignore_exists('TestAddress', 'TestQueue', false)

  session.consumer('TestQueue') do |consumer|
    # Receive a single message, return immediately if no message available
    if message = consumer.receive_immediate
      puts "Received:[#{message.body}]"
      message.acknowledge
    else
      puts "No message found"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-hornetq-0.5.0.alpha examples/producer-consumer/consumer.rb