class Qpid::Messaging::Connection

Establishes a connection to a remote endpoint.

Public Class Methods

new(opts = {}) click to toggle source

Creates a connection object, but does not actually connect to the specified location.

Options

:url - the URL for the broker (def. +"localhost"+)
:options - connection options (def. +{}+)

Controlling Reconnect Behavior

The following connection options can be used to configure the reconnection behavior for this connection.

  • :username

  • :password

  • :heartbeat

  • :tcp_nodelay

  • :sasl_mechanism

  • :sasl_service

  • :sasl_min_ssf

  • :sasl_max_ssf

  • :transport

  • :reconnect - true or false; indicates wehtehr to attempt reconnections

  • :reconnect_timeout - the number of seconds to attempt reconnecting

  • :reconnect_limit - the number of retries before reporting failure

  • :reconnect_interval_min - initial delay, in seconds, before attempting a reconnection

  • :reconnect_interval_max - number of seconds to wait before additional reconnect attempts

  • :reconnect_interval - shorthand for setting both min and max values

  • :reconnect_urls - a list of alternate URLs to use for reconnection attempts

Examples

conn = Qpid::Messaging::Connnection.new
conn = Qpid::Messaging::Connection.new :url => "amqp:tcp:broker1.domain.com:5672"
conn = Qpid::Messaging::Connection.new :options => {:username => "login", :password => "password"}
# File qpid/ruby/lib/qpid_messaging/connection.rb, line 65
def initialize(opts = {})
  @url = opts[:url] || "localhost"
  @options = convert_options(opts[:options] || {})
  @connection_impl = opts[:impl] || Cqpid::Connection.new(@url, @options)
end

Public Instance Methods

authenticated_username() click to toggle source

Returns the username used to authenticate with the connection.

# File qpid/ruby/lib/qpid_messaging/connection.rb, line 142
def authenticated_username; @connection_impl.getAuthenticatedUsername if open?; end
close() click to toggle source

Closes the connection.

# File qpid/ruby/lib/qpid_messaging/connection.rb, line 94
def close; @connection_impl.close; end
create_session(args = {}) click to toggle source

Creates a new session.

Arguments

  • :name - specifies the name for this session

  • :transactional - if true then a creates a transaction session (def. false)

Examples

session = conn.create_session :name => "session1"
session = conn.create_session :transaction => true
# File qpid/ruby/lib/qpid_messaging/connection.rb, line 108
def create_session(args = {})
  name = args[:name] || ""
  if open?
    if args[:transactional]
      session = @connection_impl.createTransactionalSession name
    else
      session = @connection_impl.createSession name
    end
    return Session.new(self, session)
  else
    raise RuntimeError.new "No connection available."
  end
end
open() click to toggle source

Establishes the connection.

Examples

conn.open unless conn.open?
# File qpid/ruby/lib/qpid_messaging/connection.rb, line 81
def open
  @connection_impl.open
end
open?() click to toggle source

Reports whether the connection is open.

Examples

conn.close if conn.open?
# File qpid/ruby/lib/qpid_messaging/connection.rb, line 91
def open?; true && !@connection_impl.nil? && @connection_impl.isOpen; end
session(name) click to toggle source

Returns a session for the specified session name.

Examples

begin
  session = conn.session "mysession"
rescue SessionNameException => error
   puts "No such session."
end
# File qpid/ruby/lib/qpid_messaging/connection.rb, line 132
def session name
  begin
    session_impl = @connection_impl.getSession name
    Qpid::Messaging::Session.new self, session_impl if session_impl
  rescue
    raise Qpid::Messaging::SessionNameException.new "No such session: #{name}"
  end
end