### Home Classes Methods

### In Files

- lib/amqp/session.rb

### Parent

AMQ::Client::EventMachineClient

### Methods

- ::authentication_failure_exception_class
- ::new
- ::tcp_connection_failure_exception_class
- #after_connection_interruption
- #after_recovery
- #auto_recover
- #auto_recovering?
- #auto_recovery?
- #before_recovery
- #broker
- #broker_endpoint
- #close
- #connected?
- #disconnect
- #handle_connection_interruption
- #host
- #hostname
- #on_closed
- #on_connection_interruption
- #on_error
- #on_open
- #on_possible_authentication_failure
- #on_recovery
- #on_tcp_connection_failure
- #on_tcp_connection_loss
- #port
- #reconnect
- #reconnect_to
- #user
- #username

### Class/Module Index

Quicksearch

- AMQP
- AMQP::Broker
- AMQP::Channel
- AMQP::ChannelClosedError
- AMQP::Client
- AMQP::Consumer
- AMQP::Error
- AMQP::Exchange
- AMQP::Header
- AMQP::IncompatibleOptionsError
- AMQP::Integration
- AMQP::Integration::Rails
- AMQP::PossibleAuthenticationFailureError
- AMQP::Queue
- AMQP::Session
- AMQP::TCPConnectionFailed
- AMQP::Utilities
- AMQP::Utilities::EventLoopHelper
- AMQP::Utilities::ServerType

No matching classes.

# AMQP::Session

AMQP session represents connection to the broker. Session objects let you define callbacks for various TCP connection lifecycle events, for instance:

- Connection is established

- Connection has failed

- Authentication has failed

- Connection is lost (there is a network failure)

- AMQP connection is opened

- AMQP connection parameters (tuning) are negotiated and accepted by the broker

- AMQP connection is properly closed

h2. Key methods

- {Session#on_connection}

- {Session#on_open}

- {Session#on_disconnection}

- {Session#on_possible_authentication_failure}

- {Session#on_tcp_connection_failure}

- {Session#on_tcp_connection_loss}

- {Session#reconnect}

- {Session#connected?}

@api public

### Attributes

server_capabilities[R]

Server capabilities (usually used to detect AMQP 0.9.1 extensions like basic.nack, publisher confirms and so on)

@return [Hash] @see files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.4.2.1.3)

server_locales[R]

Locales server supports

@see files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.4.2.1.3)

server_properties[R]

Server properties (product information, platform, et cetera)

@return [Hash] @see files.travis-ci.org/docs/amqp/0.9.1/AMQP091Reference.pdf AMQP 0.9.1 protocol documentation (Section 1.4.2.1.3)

### Public Class Methods

authentication_failure_exception_class() click to toggle source

Overrides authentication failure exception to one that inherits from AMQP::Error and thus is backwards compatible.

@private @api plugin @return [Class] AMQP::PossibleAuthenticationFailureError

    # File lib/amqp/session.rb, line 296
    def self.authentication_failure_exception_class
      @authentication_failure_exception_class ||= AMQP::PossibleAuthenticationFailureError
    end

new(*args, &block) click to toggle source

@group Connecting, reconnecting, disconnecting

    # File lib/amqp/session.rb, line 38
    def initialize(*args, &block)
      super(*args, &block)

      @client_properties.merge!({
        :platform    => ::RUBY_DESCRIPTION,
        :product     => "AMQP gem",
        :information => "http://github.com/ruby-amqp/amqp",
        :version     => AMQP::VERSION
      })
    end

tcp_connection_failure_exception_class() click to toggle source

Overrides TCP connection failure exception to one that inherits from AMQP::Error and thus is backwards compatible.

@private @api plugin @return [Class] AMQP::TCPConnectionFailed

    # File lib/amqp/session.rb, line 285
    def self.tcp_connection_failure_exception_class
      @tcp_connection_failure_exception_class ||= AMQP::TCPConnectionFailed
    end

### Public Instance Methods

after_connection_interruption(&block) click to toggle source
Alias for: on_connection_interruption
after_recovery(&block) click to toggle source
Alias for: on_recovery
auto_recover() click to toggle source

Performs recovery of channels that are in the automatic recovery mode.

@see Channel#auto_recover @see Queue#auto_recover @see Exchange#auto_recover @api plugin

    # File lib/amqp/session.rb, line 267
    def auto_recover
      super
    end

auto_recovering?() click to toggle source

@return [Boolean] whether connection is in the automatic recovery mode @api public

    # File lib/amqp/session.rb, line 255
    def auto_recovering?
      super
    end

Also aliased as: auto_recovery?
auto_recovery?() click to toggle source
Alias for: auto_recovering?
before_recovery(&block) click to toggle source

Defines a callback that will be executed after TCP connection has recovered after a network failure but before AMQP connection is re-opened. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amqp/session.rb, line 238
    def before_recovery(&block)
      super(&block)
    end

broker() click to toggle source

@return [AMQP::Broker] Broker this connection is established with

    # File lib/amqp/session.rb, line 147
    def broker
      @broker ||= AMQP::Broker.new(@server_properties)
    end

broker_endpoint() click to toggle source

@return [String] Broker endpoint in the form of HOST:PORT/VHOST @api public

    # File lib/amqp/session.rb, line 70
    def broker_endpoint
      "#{self.hostname}:#{self.port}/#{self.vhost}"
    end

close(reply_code = 200, reply_text = "Goodbye", &block) click to toggle source
Alias for: disconnect
connected?() click to toggle source

@return [Boolean] true if this AMQP connection is currently open @api plugin

    # File lib/amqp/session.rb, line 51
    def connected?
      self.opened?
    end

disconnect(reply_code = 200, reply_text = "Goodbye", &block) click to toggle source

Properly close connection with AMQ broker, as described in section 2.2.4 of the {files.travis-ci.org/docs/amqp/0.9.1/AMQP091Specification.pdf AMQP 0.9.1 specification}.

@api plugin @see close_connection

    # File lib/amqp/session.rb, line 116
    def disconnect(reply_code = 200, reply_text = "Goodbye", &block)
      # defined here to make this method appear in YARD documentation. MK.
      super(reply_code, reply_text, &block)
    end

Also aliased as: close
handle_connection_interruption() click to toggle source

@private @api plugin

    # File lib/amqp/session.rb, line 218
    def handle_connection_interruption
      super
    end

host() click to toggle source
Alias for: hostname
hostname() click to toggle source

@return [String] Broker hostname this connection uses @api public

    # File lib/amqp/session.rb, line 57
    def hostname
      @settings[:host]
    end

Also aliased as: host
on_closed(&block) click to toggle source

Defines a callback that will be run when broker confirms connection termination (client receives connection.close-ok). You can define more than one callback.

@see on_closed @api public

    # File lib/amqp/session.rb, line 174
    def on_closed(&block)
      # defined here to make this method appear in YARD documentation. MK.
      super(&block)
    end

on_connection_interruption(&block) click to toggle source

Defines a callback that will be executed after TCP connection is interrupted (typically because of a network failure). Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amqp/session.rb, line 210
    def on_connection_interruption(&block)
      super(&block)
    end

Also aliased as: after_connection_interruption
on_error(&block) click to toggle source

Defines a callback that will be executed when connection is closed after connection-level exception. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amqp/session.rb, line 228
    def on_error(&block)
      super(&block)
    end

on_open(&block) click to toggle source

Defines a callback that will be executed when AMQP connection is considered open: after client and broker has agreed on max channel identifier and maximum allowed frame size and authentication succeeds. You can define more than one callback.

@see on_closed @api public

    # File lib/amqp/session.rb, line 161
    def on_open(&block)
      # defined here to make this method appear in YARD documentation. MK.
      super(&block)
    end

on_possible_authentication_failure(&block) click to toggle source

Defines a callback that will be run when TCP connection is closed before authentication finishes. Usually this means authentication failure. You can define only one callback.

@api public

    # File lib/amqp/session.rb, line 201
    def on_possible_authentication_failure(&block)
      # defined here to make this method appear in YARD documentation. MK.
      super(&block)
    end

on_recovery(&block) click to toggle source

Defines a callback that will be executed after AMQP connection has recovered after a network failure.. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amqp/session.rb, line 247
    def on_recovery(&block)
      super(&block)
    end

Also aliased as: after_recovery
on_tcp_connection_failure(&block) click to toggle source

Defines a callback that will be run when initial TCP connection fails. You can define only one callback.

@api public

    # File lib/amqp/session.rb, line 183
    def on_tcp_connection_failure(&block)
      # defined here to make this method appear in YARD documentation. MK.
      super(&block)
    end

on_tcp_connection_loss(&block) click to toggle source

Defines a callback that will be run when TCP connection to AMQP broker is lost (interrupted). You can define only one callback.

@api public

    # File lib/amqp/session.rb, line 192
    def on_tcp_connection_loss(&block)
      # defined here to make this method appear in YARD documentation. MK.
      super(&block)
    end

port() click to toggle source

@return [String] Broker port this connection uses @api public

    # File lib/amqp/session.rb, line 64
    def port
      @settings[:port]
    end

reconnect(force = false, period = 2) click to toggle source

Reconnect to the broker using current connection settings.

@param [Boolean] force Enforce immediate connection @param [Fixnum] period If given, reconnection will be delayed by this period, in seconds. @api public

    # File lib/amqp/session.rb, line 87
    def reconnect(force = false, period = 2)
      # we do this to make sure this method shows up in our documentation
      # this method is too important to leave out and YARD currently does not
      # support cross-referencing to dependencies. MK.
      super(force, period)
    end

reconnect_to(connection_string_or_options = {}, period = 2) click to toggle source

A version of reconnect that allows connecting to different endpoints (hosts). @see reconnect @api public

    # File lib/amqp/session.rb, line 97
    def reconnect_to(connection_string_or_options = {}, period = 2)
      opts = case connection_string_or_options
             when String then
               AMQP::Client.parse_connection_uri(connection_string_or_options)
             when Hash then
               connection_string_or_options
             else
               Hash.new
             end

      super(opts, period)
    end

user() click to toggle source
Alias for: username
username() click to toggle source

@return [String] Username used by this connection @api public

    # File lib/amqp/session.rb, line 76
    def username
      @settings[:user]
    end

Also aliased as: user

[Validate]

Generated with the Darkfish Rdoc Generator 2.