Class: Surfliner::Mq::ConnectionConfig
- Inherits:
-
Object
- Object
- Surfliner::Mq::ConnectionConfig
- Defined in:
- lib/surfliner/mq/connection_config.rb
Overview
An object encapsulating RabbitMQ configuration.
Constant Summary collapse
- FALSE_VALUES =
Returns values of RABBITMQ_AWAIT_ON_CLOSE interpreted as false.
([""] + %w[0 off Off OFF f false False FALSE F n no No NO N]).freeze
Instance Attribute Summary collapse
-
#await_response_on_close ⇒ Boolean
readonly
Whether the RabbitMQ client should wait for a response when closing the connection.
-
#host ⇒ String
readonly
The RabbitMQ hostname.
-
#opts ⇒ Hash
readonly
Additional RabbitMQ connection options (see Bunny::Session#initialize).
-
#password ⇒ String
readonly
The RabbitMQ passsword.
-
#port ⇒ String
readonly
The RabbitMQ AMQP port.
-
#username ⇒ String
readonly
The RabbitMQ username.
Class Method Summary collapse
-
.from_env(**opts) ⇒ ConnectionConfig
Reads RabbitMQ configuration from environment variables and returns it as a new
ConnectionConfigobject.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Whether
otherrepresents the same configuration as this object. -
#eql?(other) ⇒ Boolean
Whether
otherrepresents the same configuration as this object. -
#hash ⇒ Integer
The hash value of this object.
-
#initialize(host:, port:, username:, password:, await_response_on_close: true, **opts) ⇒ ConnectionConfig
constructor
Initializes a new
MqConfigobject. -
#redacted_url ⇒ String
The connection URL as a string, without the password.
-
#session_url ⇒ String
The connection URL as a string.
Constructor Details
#initialize(host:, port:, username:, password:, await_response_on_close: true, **opts) ⇒ ConnectionConfig
Initializes a new MqConfig object.
33 34 35 36 37 38 39 40 |
# File 'lib/surfliner/mq/connection_config.rb', line 33 def initialize(host:, port:, username:, password:, await_response_on_close: true, **opts) @host = host @port = port @username = username @password = password @await_response_on_close = parse_boolean(await_response_on_close) @opts = opts end |
Instance Attribute Details
#await_response_on_close ⇒ Boolean (readonly)
Returns whether the RabbitMQ client should wait for a response when closing the connection.
21 22 23 |
# File 'lib/surfliner/mq/connection_config.rb', line 21 def await_response_on_close @await_response_on_close end |
#host ⇒ String (readonly)
Returns The RabbitMQ hostname.
9 10 11 |
# File 'lib/surfliner/mq/connection_config.rb', line 9 def host @host end |
#opts ⇒ Hash (readonly)
Returns Additional RabbitMQ connection options (see Bunny::Session#initialize).
24 25 26 |
# File 'lib/surfliner/mq/connection_config.rb', line 24 def opts @opts end |
#password ⇒ String (readonly)
Returns The RabbitMQ passsword.
18 19 20 |
# File 'lib/surfliner/mq/connection_config.rb', line 18 def password @password end |
#port ⇒ String (readonly)
Returns The RabbitMQ AMQP port.
12 13 14 |
# File 'lib/surfliner/mq/connection_config.rb', line 12 def port @port end |
#username ⇒ String (readonly)
Returns The RabbitMQ username.
15 16 17 |
# File 'lib/surfliner/mq/connection_config.rb', line 15 def username @username end |
Class Method Details
.from_env(**opts) ⇒ ConnectionConfig
Reads RabbitMQ configuration from environment variables and
returns it as a new ConnectionConfig object.
| Variable | Sample value | Description |
|---|---|---|
RABBITMQ_HOST |
rabbitmq |
Hostname of RabbitMQ server |
RABBITMQ_NODE_PORT_NUMBER |
5672 |
Port name of RabbitMQ server |
RABBITMQ_USERNAME |
user |
RabbitMQ username |
RABBITMQ_PASSWORD |
bitnami |
RabbitMQ password |
RABBITMQ_AWAIT_ON_CLOSE |
false |
Whether to wait on response when closing (default = true) |
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/surfliner/mq/connection_config.rb', line 55 def from_env(**opts) ConnectionConfig.new( host: ENV.fetch("RABBITMQ_HOST"), port: ENV.fetch("RABBITMQ_NODE_PORT_NUMBER"), username: ENV.fetch("RABBITMQ_USERNAME"), password: ENV.fetch("RABBITMQ_PASSWORD"), await_response_on_close: ENV["RABBITMQ_AWAIT_ON_CLOSE"] || true, **opts ) end |
Instance Method Details
#==(other) ⇒ Boolean
Whether other represents the same configuration as this object.
Note that if any attributes or connection options are modified, equality becomes unstable.
87 88 89 90 |
# File 'lib/surfliner/mq/connection_config.rb', line 87 def ==(other) return unless other.class == self.class other. == end |
#eql?(other) ⇒ Boolean
Whether other represents the same configuration as this object.
Note that if any attributes or connection options are modified, equality becomes unstable.
80 81 82 |
# File 'lib/surfliner/mq/connection_config.rb', line 80 def eql?(other) self == other end |
#hash ⇒ Integer
The hash value of this object. Equal configurations will have equal hash values. Note that if any attributes or connection options are modified, the hash value becomes unstable.
95 96 97 |
# File 'lib/surfliner/mq/connection_config.rb', line 95 def hash .hash end |
#redacted_url ⇒ String
Returns the connection URL as a string, without the password.
73 74 75 |
# File 'lib/surfliner/mq/connection_config.rb', line 73 def redacted_url @redacted_url ||= session_url.sub(password, "REDACTED") end |
#session_url ⇒ String
Returns the connection URL as a string.
68 69 70 |
# File 'lib/surfliner/mq/connection_config.rb', line 68 def session_url @session_url ||= "amqp://#{username}:#{password}@#{host}:#{port}" end |