Sha256: 589bd8fabe55e023be3aff24771796d908ee1e52e00a026a1c9f6e8f42091c0b

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 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::Connection.start_session('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

5 entries across 5 versions & 1 rubygems

Version Path
jruby-hornetq-0.4.0 examples/resque/processor.rb
jruby-hornetq-0.3.3 examples/resque/processor.rb
jruby-hornetq-0.3.2 examples/resque/processor.rb
jruby-hornetq-0.3.1 examples/resque/processor.rb
jruby-hornetq-0.3.0.alpha examples/resque/processor.rb