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.
-
#start ⇒ Object
Opening a connection with RabbitMQ.
-
#transaction_long ⇒ Object
Create an transaction with rabbitmq and not close.
-
#transaction_short(&block) ⇒ Object
Create an transaction with rabbitmq and close after response is received.
Constructor Details
#initialize ⇒ Connect
Initialize connection to server RabbitMQ
12 13 14 |
# File 'lib/rrj/rabbit/connect.rb', line 12 def initialize @rabbit = Bunny.new(bunny_conf) end |
Instance Method Details
#channel ⇒ Object
Create an channel
58 59 60 |
# File 'lib/rrj/rabbit/connect.rb', line 58 def channel @rabbit.create_channel end |
#close ⇒ Object
Close connection to server RabbitMQ
53 54 55 |
# File 'lib/rrj/rabbit/connect.rb', line 53 def close @rabbit.close end |
#start ⇒ Object
Opening a connection with RabbitMQ
48 49 50 |
# File 'lib/rrj/rabbit/connect.rb', line 48 def start @rabbit.start end |
#transaction_long ⇒ Object
Create an transaction with rabbitmq and not close
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rrj/rabbit/connect.rb', line 34 def transaction_long raise RubyRabbitmqJanus::Errors::Connect::MissingAction \ unless block_given? Timeout.timeout(60) do start yield end rescue Timeout::Error raise RubyRabbitmqJanus::Errors::Connect::TransactionTimeout, \ 'The "Long transaction" have raised Timeout exception.' end |
#transaction_short(&block) ⇒ Object
Create an transaction with rabbitmq and close after response is received
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rrj/rabbit/connect.rb', line 17 def transaction_short(&block) raise RubyRabbitmqJanus::Errors::Connect::MissingAction unless block response = nil Timeout.timeout(5) do response = transaction_long(&block) end rescue Timeout::Error raise RubyRabbitmqJanus::Errors::Connect::TransactionTimeout, \ 'The "Short transaction" have raised Timeout exception.' ensure close response end |