Sha256: c2da3c3098eeff8b3cd95309af75aece40145112649fb5b180e18e78b340ef5a

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

#
# HornetQ Requestor (Client):
#      Submit a request and wait for a reply
#      Uses the Requestor Pattern
#      The Server (server.rb) must be running first, otherwise this example 
#      program will eventually timeout
#

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

require 'rubygems'
require 'hornetq'

timeout = (ARGV[0] || 5000).to_i

# Using Connect.start since a session must be started in order to consume messages
HornetQ::Client::Connection.start_session('hornetq://localhost') do |session|
  
  # Create a non-durable ServerQueue to receive messages sent to the ServerAddress
  session.create_queue_ignore_exists('ServerAddress', 'ServerQueue', false)

  # Use Requestor (Client) Pattern to do a "RPC like" call to a server
  # Under the covers the requestor creates a temporary dynamic reply to queue
  # for the server to send the reply message to
  session.requestor('ServerAddress') do |requestor|
    # Create non-durable message
    message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
    message.body = "Some request data"
  
    # Send message to the address
    puts "Send request message and wait for Reply"
    if reply = requestor.request(message, timeout)
      puts "Received Response: #{reply.inspect}"
    else
      puts "Time out, No reply received after #{timeout/1000} seconds"
    end
  
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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