class Qpid::Messaging::Receiver

Receiver is the entity through which messages are received.

An instance of Receiver can only be created using an active (not previously closed) Session.

Example

conn     = Qpid::Messaging::Connection.new :url => "mybroker:5762"
conn.open
session  = conn.create_session
receiver = session.create_receiver "my-sender-queue"

Public Instance Methods

available() click to toggle source

Returns the number of slots for receiving messages.

This differs from capacity in that it is the available slots in the capacity for holding incoming messages, where available <= capacity.

Examples

puts "You can receive #{rcv.available} messages before blocking."
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 137
def available; @receiver_impl.getAvailable; end
capacity() click to toggle source

Returns the capacity.

The capacity is the numnber of incoming messages that can be held locally before being fetched.

Examples

puts "The receiver can hold #{rcv.capacity} messages."
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 126
def capacity; @receiver_impl.getCapacity; end
capacity=(capacity) click to toggle source

Sets the capacity for this Receiver.

Options

  • capacity - the capacity

Examples

receiver.capacity = 50 # sets the incoming capacity to 50 messages
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 114
def capacity=(capacity); @receiver_impl.setCapacity capacity; end
close() click to toggle source

Closes this Receiver.

This does not affect the Session.

# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 151
def close; @receiver_impl.close; end
closed?() click to toggle source

Returns whether the receiver is closed.

Examples

recv.close unless recv.closed?
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 159
def closed?; @receiver_impl.isClosed; end
fetch(duration = Qpid::Messaging::Duration::FOREVER) click to toggle source

Retrieves a message from the receiver’s subscription, or waits for up to the duration specified for one to become available.

If a block is given, then it will be invaked after the next message is received or the call times out, passing in the message or nil respectively.

Options

  • duration - the timeout to wait (def. Duration::FOREVER)

Examples

msg = rcvr.fetch # Uses the default timeout of forever

msg = rcvr.fetch Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately

# passes in a block to handle the received message
rcvr.fetch Qpid::Messaging::Duration::SECOND do |message|
  if message.nil?
    puts "No message was received."
  else
    puts "Received this message: #{message.content}"
  end
end
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 99
def fetch(duration = Qpid::Messaging::Duration::FOREVER)
  message_impl = @receiver_impl.fetch duration.duration_impl
  create_message_wrapper message_impl unless message_impl.nil?
end
get(duration = Qpid::Messaging::Duration::FOREVER) click to toggle source

Retrieves a message from the local queue, or waits for up to the duration specified for one to become available.

If a block is given, then it will be invaked after the next message is received or the call times out, passing in the message or nil respectively.

Options

  • duration - the timeout to wait (def. Duration::FOREVER)

Examples

msg = rcvr.get # Uses the default timeout of forever

msg = rcvr.get Qpid::Messaging::Duration::IMMEDIATE # returns a message or exits immediately

# passes in a block to handle the received message
rcvr.get Qpid::Messaging::Duration::SECOND do |message|
  if message.nil?
    puts "No message was received."
  else
    puts "Received this message: #{message.content}"
  end
end
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 70
def get(duration = Qpid::Messaging::Duration::FOREVER)
  message_impl = @receiver_impl.get duration.duration_impl
  create_message_wrapper message_impl unless message_impl.nil?
end
name() click to toggle source

Returns the name of this Receiver.

Examples

puts "Receiver: #{recv.name}"
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 166
def name; @receiver_impl.getName; end
session() click to toggle source

Returns the Session for this Receiver.

# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 169
def session; @session; end
unsettled() click to toggle source

Returns the number of messages that have been received and acknowledged but whose acknowledgements have not been confirmed by the sender.

Examples

puts "You have #{rcv.unsettled} messages to be confirmed."
# File qpid/ruby/lib/qpid_messaging/receiver.rb, line 146
def unsettled; @receiver_impl.getUnsettled; end