Sha256: c3e828e421f998ba737c9ef66672ee6e76a68f85aafccccf23501dc80cddbf71

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

#
# Processor:
#    Process requests submitted by Resque Worker and reply
#

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

require 'rubygems'
require 'hornetq'

# Let server shutdown on its own after 5 minutes of inactivity. Set to 0 to wait forever
timeout = (ARGV[0] || 300000).to_i

q_name = 'processor'

HornetQ::Client::Factory.start('hornetq://localhost') do |session|
  begin
    # Create durable queue with matching address
    session.create_queue(q_name, q_name, true)
  rescue
    # Ignore when queue already exists
  end
  
  server = session.create_server(q_name, timeout)

  puts "Waiting for Requests..."  
  server.run do |request_message|
    print "."
    
    # Create Reply Message
    reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
    reply_message.body = "Echo [#{request_message.body}]"
    
    # The result of the block is the message to be sent back, or nil if no reply
    reply_message
  end

  # Server will stop after timeout period after no messages received. Set to 0 to wait forever
  server.close
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-hornetq-0.2.5.alpha examples/client/resque/processor.rb