Menu Search

server.rb

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'qpid_messaging'

if __FILE__ == $0
  broker  = ARGV[0] || "amqp:tcp:localhost:5672"
  options = ARGV[1] || ""

  connection = Qpid::Messaging::Connection.new :url => broker, :options =>options
  connection.open
  session = connection.create_session
  receiver = session.create_receiver "service_queue; {create:always}"

  loop do
    request = receiver.fetch
    address = request.reply_to

    if !address.nil?
      sender = session.create_sender address
      response = Qpid::Messaging::Message.new :content => request.content_object.upcase
      sender.send response
      puts "Processed request: #{request.content_object} -> #{response.content_object}"
      session.acknowledge
    else
      puts "Error: no reply address specified for request: #{request.content_object}"
      session.reject request
    end
  end

  connection.close
end

Download this file