A Session represents a distinct conversation between end points.
Acknowledges one or more outstanding messages that have been received on this session.
:message - if specified, then only the Message
specified is
acknowledged
:sync - if true then the call will block until processed by the server (def. false)
session.acknowledge # acknowledges all received messages session.acknowledge :message => message # acknowledge one message session.acknowledge :sync => true # blocks until the call completes
# File lib/qpid/session.rb, line 173 def acknowledge(args = {}) sync = args[:sync] || false message = args[:message] if args[:message] unless message.nil? @session_impl.acknowledge message.message_impl, sync else @session_impl.acknowledge sync end end
Closes the Session
and all associated Sender
and
Receiver
instances.
NOTE: All Session
instances for a Connection
are
closed when the Connection
is closed.
# File lib/qpid/session.rb, line 148 def close; @session_impl.close; end
Commits any pending transactions for a transactional session.
# File lib/qpid/session.rb, line 151 def commit; @session_impl.commit; end
Returns the Connection
associated with this session.
# File lib/qpid/session.rb, line 43 def connection @connection end
Creates a new endpoint for receiving messages.
The address
can either be an instance Address
or
else a string that describes an address endpoint.
address
The end point address.
receiver = session.create_receiver "my-queue"
# File lib/qpid/session.rb, line 107 def create_receiver(address) result = nil receiver_impl = nil if address.class == Qpid::Messaging::Address address_impl = address.address_impl receiver_impl = @session_impl.createReceiver address_impl else receiver_impl = @session_impl.createReceiver(address) end receiver_name = receiver_impl.getName @receivers[receiver_name] = Qpid::Messaging::Receiver.new self, receiver_impl @receivers[receiver_name] end
Creates a new endpoint for sending messages.
The address
can either be an instance Address
or
else a string that describes an address endpoint.
address
The end point address.
sender = session.create_sender "my-queue;{create:always}"
# File lib/qpid/session.rb, line 60 def create_sender(address) _address = address if address.class == Qpid::Messaging::Address _address = address.address_impl end sender_impl = @session_impl.createSender(_address) sender_name = sender_impl.getName @senders[sender_name] = Qpid::Messaging::Sender.new(self, sender_impl) @senders[sender_name] end
If the Session
has been rendered invalid due to some
exception, this method will result in that exception being raised.
If none have occurred, then no exceptions are raised.
if @session.errors? begin @session.errors rescue Exception => error puts "An error occurred: #{error}" end end
# File lib/qpid/session.rb, line 264 def errors; @session_impl.checkError; end
Returns true if there were exceptions on this session.
puts "There were session errors." if @session.errors?
# File lib/qpid/session.rb, line 248 def errors?; @session_impl.hasError; end
Fetches the Receiver
for the next message.
timeout - time to wait for a Receiver
before timing out
recv = session.next_receiver # wait forever for the next +Receiver+ # execute a block on the next receiver session.next_receiver do |recv| msg = recv.get puts "Received message: #{msg.content}" end
# File lib/qpid/session.rb, line 232 def next_receiver(timeout = Qpid::Messaging::Duration::FOREVER, &block) receiver_impl = @session_impl.nextReceiver(timeout.duration_impl) unless receiver_impl.nil? recv = Qpid::Messaging::Receiver.new self, receiver_impl block.call recv unless block.nil? end return recv end
Returns the total number of receivable messages, and messages already
received, by Receiver
instances associated with this
Session
.
# File lib/qpid/session.rb, line 212 def receivable; @session_impl.getReceivable; end
Retrieves the Receiver
with the specified name.
The Receiver
must have been previously created using the
create_receiver
method.
name
The Receiver
name.
receiver = session.receiver "my-queue"
# File lib/qpid/session.rb, line 138 def receiver(name) raise Qpid::Messaging::KeyError, "No such receiver: #{name}" unless @receivers.has_key? name @receivers[name] end
Rejects the specified message. A rejected message will not be redelivered.
NOTE: A message cannot be rejected once it has been acknowledged.
# File lib/qpid/session.rb, line 188 def reject(message); @session_impl.reject message.message_impl; end
Releases the message, which allows the broker to attempt to redeliver it.
NOTE: A message connot be released once it has been acknowled.
# File lib/qpid/session.rb, line 194 def release(message); @session_impl.release message.message_impl; end
Rolls back any uncommitted transactions on a transactional session.
# File lib/qpid/session.rb, line 154 def rollback; @session_impl.rollback; end
Retrieves the Sender
with the specified name.
The Sender
must have been previously created using the
create_sender
method.
name
The Sender
name.
sender = session.sender "my-queue"
# File lib/qpid/session.rb, line 88 def sender(name) raise Qpid::Messaging::KeyError, "No such sender: #{name}" unless @senders.has_key? name @senders[name] end
Requests synchronization with the server.
:block - if true then the call blocks until the server acknowledges it (def. false)
# File lib/qpid/session.rb, line 205 def sync(args = {}) block = args[:block] || false @session_impl.sync block end
Returns the number of messages that have been acknowledged by this session whose acknowledgements have not been confirmed as processed by the server.
# File lib/qpid/session.rb, line 216 def unsettled_acks; @session_impl.getUnsettledAcks; end