Class: AMQ::Client::Connection
- Inherits:
-
Entity
- Object
- Entity
- AMQ::Client::Connection
- Includes:
- StatusMixin
- Defined in:
- lib/amq/client/amqp/connection.rb
Overview
AMQP connection object handles various connection lifecycle events (for example, Connection.Start-Ok, Connection.Tune-Ok and Connection.Close methods)
AMQP connection has multiple channels accessible via #channels reader.
Constant Summary
- CLIENT_PROPERTIES =
TODO: make it possible to override these from, say, amqp gem or bunny
{ :platform => ::RUBY_DESCRIPTION, :product => "AMQ Client", :version => AMQ::Client::VERSION, :homepage => "https://github.com/ruby-amqp/amq-client" }.freeze
Constants included from StatusMixin
Instance Attribute Summary (collapse)
-
- (Object) channel_max
Maximum channel number that the server permits this connection to use.
-
- (Object) channels
readonly
Channels within this connection.
-
- (Object) frame_max
Maximum frame size that the server permits this connection to use.
-
- (Object) heartbeat
The delay, in seconds, of the connection heartbeat that the server wants.
-
- (Object) known_hosts
readonly
Returns the value of attribute known_hosts.
-
- (Object) locale
readonly
The locale defines the language in which the server will send reply texts.
-
- (Object) mechanism
readonly
Authentication mechanism used.
-
- (Object) response
readonly
Security response data.
-
- (Object) server_properties
Authentication mechanism used.
Attributes included from StatusMixin
Attributes inherited from Entity
Instance Method Summary (collapse)
-
- (Object) close(reply_code = 200, reply_text = "Goodbye",, class_id = 0, method_id = 0)
Sends Connection.Close to the server.
-
- (Object) close_ok(method)
Handles connection.close-ok.
-
- (Object) handle_close(method)
Handles Connection.Close-Ok.
- - (Object) handle_open_ok(method)
-
- (Connection) initialize(client, mechanism, response, locale)
constructor
A new instance of Connection.
-
- (Object) open(vhost = "/"))
Sends Connection.Open to the server.
-
- (Object) start_ok
Connection class methods.
- - (Object) tune_ok(method)
Methods included from StatusMixin
#closed!, #closed?, #closing!, #closing?, #opened!, #opened?, #opening!, #opening?
Methods inherited from Entity
#error, #exec_callback, handle, handlers
Constructor Details
- (Connection) initialize(client, mechanism, response, locale)
A new instance of Connection
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/amq/client/amqp/connection.rb', line 82 def initialize(client, mechanism, response, locale) @mechanism = mechanism @response = response @locale = locale @channels = Hash.new super(client) # Default errback. # You might want to override it, otherwise it'll # crash your program. It's the expected behaviour # if it's a synchronous one, but not if you use # some kind of event loop like EventMachine etc. self.callbacks[:close] = Proc.new do |exception| raise exception end end |
Instance Attribute Details
- (Object) channel_max
Maximum channel number that the server permits this connection to use. Usable channel numbers are in the range 1..channel_max. Zero indicates no specified limit.
64 65 66 |
# File 'lib/amq/client/amqp/connection.rb', line 64 def channel_max @channel_max end |
- (Object) channels (readonly)
Channels within this connection.
57 58 59 |
# File 'lib/amq/client/amqp/connection.rb', line 57 def channels @channels end |
- (Object) frame_max
Maximum frame size that the server permits this connection to use.
69 70 71 |
# File 'lib/amq/client/amqp/connection.rb', line 69 def frame_max @frame_max end |
- (Object) heartbeat
The delay, in seconds, of the connection heartbeat that the server wants. Zero means the server does not want a heartbeat.
75 76 77 |
# File 'lib/amq/client/amqp/connection.rb', line 75 def heartbeat @heartbeat end |
- (Object) known_hosts (readonly)
Returns the value of attribute known_hosts
77 78 79 |
# File 'lib/amq/client/amqp/connection.rb', line 77 def known_hosts @known_hosts end |
- (Object) locale (readonly)
The locale defines the language in which the server will send reply texts.
52 53 54 |
# File 'lib/amq/client/amqp/connection.rb', line 52 def locale @locale end |
- (Object) mechanism (readonly)
Authentication mechanism used.
42 43 44 |
# File 'lib/amq/client/amqp/connection.rb', line 42 def mechanism @mechanism end |
- (Object) response (readonly)
Security response data.
47 48 49 |
# File 'lib/amq/client/amqp/connection.rb', line 47 def response @response end |
- (Object) server_properties
Authentication mechanism used.
37 38 39 |
# File 'lib/amq/client/amqp/connection.rb', line 37 def server_properties @server_properties end |
Instance Method Details
- (Object) close(reply_code = 200, reply_text = "Goodbye",, class_id = 0, method_id = 0)
Sends Connection.Close to the server.
155 156 157 158 |
# File 'lib/amq/client/amqp/connection.rb', line 155 def close(reply_code = 200, reply_text = "Goodbye", class_id = 0, method_id = 0) @client.send Protocol::Connection::Close.encode(reply_code, reply_text, class_id, method_id) closing! end |
- (Object) close_ok(method)
Handles connection.close-ok
163 164 165 166 |
# File 'lib/amq/client/amqp/connection.rb', line 163 def close_ok(method) closed! @client.disconnection_successful end |
- (Object) handle_close(method)
Handles Connection.Close-Ok
144 145 146 147 148 149 150 |
# File 'lib/amq/client/amqp/connection.rb', line 144 def handle_close(method) self.channels.each { |key, value| value.status = :closed } closed! # TODO: use proper exception class, provide protocol class (we know method.class_id and method.method_id) as well! self.error RuntimeError.new(method.reply_text) end |
- (Object) handle_open_ok(method)
132 133 134 135 136 137 138 139 |
# File 'lib/amq/client/amqp/connection.rb', line 132 def handle_open_ok(method) @known_hosts = method.known_hosts opened! # async adapters need this callback to proceed with # Adapter.connect block evaluation @client.connection_successful if @client.respond_to?(:connection_successful) end |
- (Object) open(vhost = "/"))
Sends Connection.Open to the server.
124 125 126 |
# File 'lib/amq/client/amqp/connection.rb', line 124 def open(vhost = "/") @client.send Protocol::Connection::Open.encode(vhost) end |
- (Object) start_ok
Connection class methods
105 106 107 108 109 110 111 |
# File 'lib/amq/client/amqp/connection.rb', line 105 def start_ok # it's not clear whether we should transition to :opening state here # or in #open but in case authentication fails, it would be strange to have # @status undefined. So lets do this. MK. opening! @client.send Protocol::Connection::StartOk.encode({}, self.mechanism, self.response, self.locale) end |
- (Object) tune_ok(method)
113 114 115 116 117 118 119 |
# File 'lib/amq/client/amqp/connection.rb', line 113 def tune_ok(method) @channel_max = method.channel_max @frame_max = method.frame_max @heartbeat = method.heartbeat @client.send Protocol::Connection::TuneOk.encode(@channel_max, @frame_max, @heartbeat) end |