Sha256: 1d6cf8eef0c527d84bec3abd942588c87a27996447af73a1d5bf75cf15f0b853

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

#
# HornetQ Consumer:
#      Reply to a request
#      Implements the Server Pattern
#      The reply message is sent back to the reply to address supplied by the
#      requestor
#

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

require 'rubygems'
require 'hornetq'

# By default the server will shutdown after 60 seconds, set to 0 to never shutdown
timeout = (ARGV[0] || 60000).to_i

HornetQ::Client::Connection.start_session(:connection=> {:uri => 'hornetq://localhost'}) do |session|
  # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
  session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)

  session.server('ServerQueue', timeout) do |server|
    puts "Waiting for Requests..."  
    server.run do |request_message|
      puts "Received:[#{request_message.inspect}]"
    
      # Create Reply Message
      reply_message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, false)
      reply_message.body = "Echo [#{request_message.body}]"
    
      # The result of this block is the message to be sent back to the requestor (client)
      # Or, nil if no response should be sent back
      reply_message
    end
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jruby-hornetq-0.4.0 examples/client-server/server.rb
jruby-hornetq-0.3.3 examples/client-server/server.rb
jruby-hornetq-0.3.2 examples/client-server/server.rb
jruby-hornetq-0.3.1 examples/client-server/server.rb
jruby-hornetq-0.3.0.alpha examples/client-server/server.rb