Class: AMQP::Session
- Inherits:
-
AMQ::Client::EventMachineClient
- Object
- AMQ::Client::EventMachineClient
- AMQP::Session
- Defined in:
- lib/amqp/session.rb
Overview
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
Key methods
- Session#on_connection
- #on_open
- Session#on_disconnection
- #on_possible_authentication_failure
- #on_tcp_connection_failure
- #on_tcp_connection_loss
- #reconnect
- #connected?
Broker information (collapse)
-
- (Hash) server_capabilities
readonly
Server capabilities (usually used to detect AMQP 0.9.1 extensions like basic.nack, publisher confirms and so on).
-
- (Object) server_locales
readonly
Locales server supports.
-
- (Hash) server_properties
readonly
Server properties (product information, platform, et cetera).
Connecting, reconnecting, disconnecting (collapse)
-
- (String) broker_endpoint
Broker endpoint in the form of HOST:PORT/VHOST.
-
- (Boolean) connected?
True if this AMQP connection is currently open.
-
- (Object) disconnect(reply_code = 200, reply_text = "Goodbye", &block)
(also: #close)
Properly close connection with AMQ broker, as described in section 2.2.4 of the AMQP 0.9.1 specification.
-
- (String) hostname
(also: #host)
Broker hostname this connection uses.
-
- (Session) initialize(*args, &block)
constructor
A new instance of Session.
-
- (String) port
Broker port this connection uses.
-
- (Object) reconnect(force = false, period = 2)
Reconnect to the broker using current connection settings.
-
- (Object) reconnect_to(connection_string_or_options = {}, period = 2)
A version of #reconnect that allows connecting to different endpoints (hosts).
-
- (String) username
(also: #user)
Username used by this connection.
Broker information (collapse)
-
- (AMQP::Broker) broker
Broker this connection is established with.
Error Handling and Recovery (collapse)
-
- (Object) auto_recover
Performs recovery of channels that are in the automatic recovery mode.
-
- (Boolean) auto_recovering?
(also: #auto_recovery?)
Whether connection is in the automatic recovery mode.
-
- (Object) before_recovery(&block)
Defines a callback that will be executed after TCP connection has recovered after a network failure but before AMQP connection is re-opened.
-
- (Object) on_closed(&block)
Defines a callback that will be run when broker confirms connection termination (client receives connection.close-ok).
-
- (Object) on_connection_interruption(&block)
(also: #after_connection_interruption)
Defines a callback that will be executed after TCP connection is interrupted (typically because of a network failure).
-
- (Object) on_error(&block)
Defines a callback that will be executed when connection is closed after connection-level exception.
-
- (Object) on_possible_authentication_failure(&block)
Defines a callback that will be run when TCP connection is closed before authentication finishes.
-
- (Object) on_recovery(&block)
(also: #after_recovery)
Defines a callback that will be executed after AMQP connection has recovered after a network failure..
-
- (Object) on_tcp_connection_failure(&block)
Defines a callback that will be run when initial TCP connection fails.
-
- (Object) on_tcp_connection_loss(&block)
Defines a callback that will be run when initial TCP connection fails.
Instance Method Summary (collapse)
-
- (Object) on_open(&block)
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.
Constructor Details
- (Session) initialize(*args, &block)
A new instance of Session
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/amqp/session.rb', line 39 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 |
Instance Attribute Details
- (Hash) server_capabilities (readonly)
Server capabilities (usually used to detect AMQP 0.9.1 extensions like basic.nack, publisher confirms and so on)
140 141 142 |
# File 'lib/amqp/session.rb', line 140 def server_capabilities @server_capabilities end |
- (Object) server_locales (readonly)
Locales server supports
145 146 147 |
# File 'lib/amqp/session.rb', line 145 def server_locales @server_locales end |
- (Hash) server_properties (readonly)
Server properties (product information, platform, et cetera)
133 134 135 |
# File 'lib/amqp/session.rb', line 133 def server_properties @server_properties end |
Instance Method Details
- (Object) auto_recover
Performs recovery of channels that are in the automatic recovery mode.
268 269 270 |
# File 'lib/amqp/session.rb', line 268 def auto_recover super end |
- (Boolean) auto_recovering? Also known as: auto_recovery?
Whether connection is in the automatic recovery mode
256 257 258 |
# File 'lib/amqp/session.rb', line 256 def auto_recovering? super end |
- (Object) before_recovery(&block)
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).
239 240 241 |
# File 'lib/amqp/session.rb', line 239 def before_recovery(&block) super(&block) end |
- (AMQP::Broker) broker
Broker this connection is established with
148 149 150 |
# File 'lib/amqp/session.rb', line 148 def broker @broker ||= AMQP::Broker.new(@server_properties) end |
- (String) broker_endpoint
Broker endpoint in the form of HOST:PORT/VHOST
71 72 73 |
# File 'lib/amqp/session.rb', line 71 def broker_endpoint "#{self.hostname}:#{self.port}/#{self.vhost}" end |
- (Boolean) connected?
True if this AMQP connection is currently open
52 53 54 |
# File 'lib/amqp/session.rb', line 52 def connected? self.opened? end |
- (Object) disconnect(reply_code = 200, reply_text = "Goodbye", &block) Also known as: close
Properly close connection with AMQ broker, as described in section 2.2.4 of the AMQP 0.9.1 specification.
117 118 119 120 |
# File 'lib/amqp/session.rb', line 117 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 |
- (String) hostname Also known as: host
Broker hostname this connection uses
58 59 60 |
# File 'lib/amqp/session.rb', line 58 def hostname @settings[:host] end |
- (Object) on_closed(&block)
Defines a callback that will be run when broker confirms connection termination (client receives connection.close-ok). You can define more than one callback.
175 176 177 178 |
# File 'lib/amqp/session.rb', line 175 def on_closed(&block) # defined here to make this method appear in YARD documentation. MK. super(&block) end |
- (Object) on_connection_interruption(&block) Also known as: after_connection_interruption
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).
211 212 213 |
# File 'lib/amqp/session.rb', line 211 def on_connection_interruption(&block) super(&block) end |
- (Object) on_error(&block)
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).
229 230 231 |
# File 'lib/amqp/session.rb', line 229 def on_error(&block) super(&block) end |
- (Object) on_open(&block)
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.
162 163 164 165 |
# File 'lib/amqp/session.rb', line 162 def on_open(&block) # defined here to make this method appear in YARD documentation. MK. super(&block) end |
- (Object) on_possible_authentication_failure(&block)
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.
202 203 204 205 |
# File 'lib/amqp/session.rb', line 202 def on_possible_authentication_failure(&block) # defined here to make this method appear in YARD documentation. MK. super(&block) end |
- (Object) on_recovery(&block) Also known as: after_recovery
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).
248 249 250 |
# File 'lib/amqp/session.rb', line 248 def on_recovery(&block) super(&block) end |
- (Object) on_tcp_connection_failure(&block)
Defines a callback that will be run when initial TCP connection fails. You can define only one callback.
184 185 186 187 |
# File 'lib/amqp/session.rb', line 184 def on_tcp_connection_failure(&block) # defined here to make this method appear in YARD documentation. MK. super(&block) end |
- (Object) on_tcp_connection_loss(&block)
Defines a callback that will be run when initial TCP connection fails. You can define only one callback.
193 194 195 196 |
# File 'lib/amqp/session.rb', line 193 def on_tcp_connection_loss(&block) # defined here to make this method appear in YARD documentation. MK. super(&block) end |
- (String) port
Broker port this connection uses
65 66 67 |
# File 'lib/amqp/session.rb', line 65 def port @settings[:port] end |
- (Object) reconnect(force = false, period = 2)
Reconnect to the broker using current connection settings.
88 89 90 91 92 93 |
# File 'lib/amqp/session.rb', line 88 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 |
- (Object) reconnect_to(connection_string_or_options = {}, period = 2)
A version of #reconnect that allows connecting to different endpoints (hosts).
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/amqp/session.rb', line 98 def reconnect_to( = {}, period = 2) opts = case when String then AMQP::Client.parse_connection_uri() when Hash then else Hash.new end super(opts, period) end |
- (String) username Also known as: user
Username used by this connection
77 78 79 |
# File 'lib/amqp/session.rb', line 77 def username @settings[:user] end |