Class: LontaraUtilities::RMQ::Connection
- Inherits:
-
Object
- Object
- LontaraUtilities::RMQ::Connection
- Defined in:
- lib/lontara_utilities/rmq/connection.rb
Overview
Initializing the connection to RabbitMQ.
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(url: ENV['RABBITMQ_URL'], default_exchange: true) ⇒ Connection
constructor
**Connection can be initialized within a block.**.
Constructor Details
#initialize(url: ENV['RABBITMQ_URL'], default_exchange: true) ⇒ Connection
**Connection can be initialized within a block.**
If block is given, connection object will be yielded. You can use the object to define the ‘exchange`, `queue`, or `reply queue`.
Example:
def initialize(url, queue, reply_queue)
Connection.new(url:) do |conn|
@exchange = conn.channel.default_exchange
@queue = conn.channel.queue(queue)
@reply_queue = conn.channel.queue(reply_queue, exclusive: true)
end
end
# ... your code goes here
22 23 24 25 26 27 28 |
# File 'lib/lontara_utilities/rmq/connection.rb', line 22 def initialize(url: ENV['RABBITMQ_URL'], default_exchange: true) @connection = Bunny.new(url) @connection.start @channel = channel_pool @exchange = channel.default_exchange if default_exchange end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
34 35 36 |
# File 'lib/lontara_utilities/rmq/connection.rb', line 34 def channel @channel end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
34 35 36 |
# File 'lib/lontara_utilities/rmq/connection.rb', line 34 def connection @connection end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
34 35 36 |
# File 'lib/lontara_utilities/rmq/connection.rb', line 34 def exchange @exchange end |
Instance Method Details
#close ⇒ Object
30 31 32 |
# File 'lib/lontara_utilities/rmq/connection.rb', line 30 def close @connection.close end |