Class: RubyRabbitmqJanus::Rabbit::Connect
- Inherits:
-
Object
- Object
- RubyRabbitmqJanus::Rabbit::Connect
- Defined in:
- lib/rrj/rabbit/connect.rb
Overview
Class for manage connection with rabbitmq
Instance Method Summary collapse
-
#channel ⇒ Object
Create an channel.
-
#close ⇒ Object
Close connection to server RabbitMQ.
-
#initialize ⇒ Connect
constructor
Initialize connection to server RabbitMQ.
-
#option_log_rabbit ⇒ Object
private
Define option logs for bunny.
-
#read_options_server ⇒ Object
private
Read option for bunny instance (connection with rabbitmq) :reek:FeatureEnvy.
-
#start ⇒ Object
Openning a connection with Rabbitmq.
-
#transaction_long ⇒ Object
Create an transaction with rabbitmq and not close.
-
#transaction_short ⇒ Object
Create an transaction with rabbitmq and close after response is received.
Constructor Details
#initialize ⇒ Connect
Initialize connection to server RabbitMQ
9 10 11 12 |
# File 'lib/rrj/rabbit/connect.rb', line 9 def initialize Tools::Log.instance.debug 'Initialize connection with RabbitMQ' @rabbit = Bunny.new() end |
Instance Method Details
#channel ⇒ Object
Create an channel
44 45 46 47 |
# File 'lib/rrj/rabbit/connect.rb', line 44 def channel Tools::Log.instance.debug 'Create an channel' @rabbit.create_channel end |
#close ⇒ Object
Close connection to server RabbitMQ
36 37 38 39 40 41 |
# File 'lib/rrj/rabbit/connect.rb', line 36 def close Tools::Log.instance.debug 'Connection to rabbitmq STOP' @rabbit.close rescue raise Bunny::ConnectionClosedError end |
#option_log_rabbit ⇒ Object (private)
Define option logs for bunny
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rrj/rabbit/connect.rb', line 63 def option_log_rabbit if Tools::Log.instance.level.zero? { log_level: Tools::Log.instance.level, log_file: Tools::Log.instance.logdev } else {} end end |
#read_options_server ⇒ Object (private)
Read option for bunny instance (connection with rabbitmq) :reek:FeatureEnvy
53 54 55 56 57 58 59 60 |
# File 'lib/rrj/rabbit/connect.rb', line 53 def cfg = Tools::Config.instance.['rabbit'] opts = {} %w(host port pass user vhost).each do |val| opts.merge!(val.to_sym => Tools::Env.instance.test_env_var(cfg, val)) end opts.merge!(option_log_rabbit) end |
#start ⇒ Object
Openning a connection with Rabbitmq
28 29 30 31 32 33 |
# File 'lib/rrj/rabbit/connect.rb', line 28 def start Tools::Log.instance.debug 'Connection to rabbitmq START' @rabbit.start rescue => raise Errors::ConnectionRabbitmqFailed, end |
#transaction_long ⇒ Object
Create an transaction with rabbitmq and not close
22 23 24 25 |
# File 'lib/rrj/rabbit/connect.rb', line 22 def transaction_long start yield end |
#transaction_short ⇒ Object
Create an transaction with rabbitmq and close after response is received
15 16 17 18 19 |
# File 'lib/rrj/rabbit/connect.rb', line 15 def transaction_short response = transaction_long { yield } close response end |