Class: Qpid::Messaging::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/qpid_messaging/sender.rb

Overview

Sender is the entity through which messages are sent.

An instance of Sender can only be created using an active (not previously closed) Session. See Qpid::Messaging::Session.create_sender for more details.

Examples

# create a connection
conn = Qpid::Messaging::Connection.new "mybroker:5672"
conn.open

if conn.open?

  # create a session
  session = conn.create_session

  # create a sender that posts messages to the "updates" queue
  sender = session.create_sender "updates;{create:always}

  # begin sending updates
  loop do
    # wait for the next event content then send it
    content = wait_for_event
    sender.send Qpid::Messaging::Message.new :content => content
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(session, sender_impl) ⇒ Sender

:nodoc:



53
54
55
56
# File 'lib/qpid_messaging/sender.rb', line 53

def initialize(session, sender_impl) # :nodoc:
  @session     = session
  @sender_impl = sender_impl
end

Instance Method Details

#availableObject

Returns the available slots for sending messages.

This differs from capacity in that it is the available slots in the senders capacity for holding outgoing messages. The difference between capacity and available is the number of messages that have not been delivered yet.



123
124
125
# File 'lib/qpid_messaging/sender.rb', line 123

def available
  @sender_impl.getAvailable
end

#capacityObject

Returns the capacity.



111
# File 'lib/qpid_messaging/sender.rb', line 111

def capacity; @sender_impl.getCapacity; end

#capacity=(capacity) ⇒ Object

Sets the capacity for this Sender.

The capacity is the number of outgoing messages that can be held pending confirmation of receipt by the broker.

Options

  • capacity - the capacity



108
# File 'lib/qpid_messaging/sender.rb', line 108

def capacity=(capacity); @sender_impl.setCapacity capacity; end

#closeObject

Closes this Sender.

This does not affect the owning Session or Connection.



95
# File 'lib/qpid_messaging/sender.rb', line 95

def close; @sender_impl.close; end

#nameObject

Returns the human-readable name for this Sender.



98
# File 'lib/qpid_messaging/sender.rb', line 98

def name; @sender_impl.getName; end

#send(message, args = {}, &block) ⇒ Object

Sends a message, optionally blocking until the message is received by the broker.

Options

  • message - The message to send.

  • :sync - Block until received. See note below on synching.

Synching

If :sync => true, then the call will block until the broker confirms receipt of the message. Otherwise it will only block for available capacity; i.e., until pending is equal to capacity.

Examples

# send a message
outgoing = Qpid::Messaging::Message.new :content => content
sender.send outgoing

# send a message, wait for confirmation from the broker
outgoing = Qpid::Messaging::Message.new :content => content
sender.send outgoing, :sync => true


86
87
88
89
90
# File 'lib/qpid_messaging/sender.rb', line 86

def send(message, args = {}, &block)
  sync = args[:sync] || false
  @sender_impl.send message.message_impl, sync
  block.call message unless block.nil?
end

#sender_implObject

:nodoc:



58
59
60
# File 'lib/qpid_messaging/sender.rb', line 58

def sender_impl # :nodoc:
  @sender_impl
end

#sessionObject

Returns the Session for this sender.



128
# File 'lib/qpid_messaging/sender.rb', line 128

def session; @session; end

#unsettledObject

Returns the number of messages sent that are pending receipt confirmation by the broker.



115
# File 'lib/qpid_messaging/sender.rb', line 115

def unsettled; @sender_impl.getUnsettled; end