Class: RubyRabbitmqJanus::Rabbit::Connect

Inherits:
Object
  • Object
show all
Defined in:
lib/rrj/rabbit/connect.rb

Overview

Class for manage connection with RabbitMQ

Author:

Instance Method Summary collapse

Constructor Details

#initializeConnect

Initialize connection to server RabbitMQ



10
11
12
13
14
# File 'lib/rrj/rabbit/connect.rb', line 10

def initialize
  @rabbit = Bunny.new(Tools::Config.instance.server_settings)
rescue => exception
  raise Errors::Rabbit::Connect::Initialize, exception
end

Instance Method Details

#channelObject

Create an channel



48
49
50
51
52
# File 'lib/rrj/rabbit/connect.rb', line 48

def channel
  @rabbit.create_channel
rescue => exception
  raise Errors::Rabbit::Connect::Channel, exception
end

#closeObject

Close connection to server RabbitMQ



41
42
43
44
45
# File 'lib/rrj/rabbit/connect.rb', line 41

def close
  @rabbit.close
rescue => exception
  raise Errors::Rabbit::Connect::Close, exception
end

#startObject

Opening a connection with RabbitMQ



34
35
36
37
38
# File 'lib/rrj/rabbit/connect.rb', line 34

def start
  @rabbit.start
rescue => exception
  raise Errors::Rabbit::Connect::Start, exception
end

#transaction_longObject

Create an transaction with rabbitmq and not close



26
27
28
29
30
31
# File 'lib/rrj/rabbit/connect.rb', line 26

def transaction_long
  start
  yield
rescue => exception
  raise Errors::Rabbit::Connect::TransactionLong, exception
end

#transaction_shortObject

Create an transaction with rabbitmq and close after response is received



17
18
19
20
21
22
23
# File 'lib/rrj/rabbit/connect.rb', line 17

def transaction_short
  response = transaction_long { yield }
  close
  response
rescue => exception
  raise Errors::Rabbit::Connect::TransactionShort, exception
end