module Qpid::Messaging

The Qpid Messaging framework is an enterprise messaging framework based on the open-source AMQP protocol.

Example Application

Here is a simple example application. It creates a link to a broker located on a system named broker.myqpiddomain.com. It then creates a new messaging queue named “qpid-examples” and publishes a message to it. It then consumes that same message and closes the connection.

require 'rubygems'
gem 'qpid_messaging'
require 'qpid_messaging'

# create a connection, open it and then create a session named "session1"
conn = Qpid::Messaging::Connection.new :name => "broker.myqpiddomain.com"
conn.open
session = conn.create_session "session1"

# create a sender and a receiver
# the sender marks the queue as one that is deleted when trhe sender disconnects
send = session.create_sender "qpid-examples;{create:always,delete:always}"
recv = session.create_receiver "qpid-examples"

# create an outgoing message and send it
outgoing = Qpid::Messaging::Message.new :content => "The time is #{Time.new}"
sender.send outgoing

# set the receiver's capacity to 10 and then check out many messages are pending
recv.capacity = 10
puts "There are #{recv.available} messages waiting." # should report 1 message

# get the nextwaiting  message, which should be in the local queue now,
# and output the contents
incoming = recv.get Qpid::Messaging::Duration::IMMEDIATE
puts "Received the following message: #{incoming.content}"
# the output should be the text that was sent earlier

# acknowledge the message, letting the sender know the message was received
puts "The sender currently has #{send.unsettled} message(s) pending."
# should report 1 unsettled message
session.acknowledge incoming # acknowledge the received message
puts "Now sender currently has #{send.unsettled} message(s) pending."
# should report 0 unsettled messages

# close the connection
conn.close