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



12
13
14
15
16
# File 'lib/rrj/rabbit/connect.rb', line 12

def initialize
  @rabbit = Bunny.new(read_options_server.merge!(option_log_rabbit))
rescue => error
  raise Errors::Rabbit::Connect::Initialize, error
end

Instance Method Details

#channelObject

Create an channel



50
51
52
53
54
# File 'lib/rrj/rabbit/connect.rb', line 50

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

#closeObject

Close connection to server RabbitMQ



43
44
45
46
47
# File 'lib/rrj/rabbit/connect.rb', line 43

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

#startObject

Openning a connection with Rabbitmq



36
37
38
39
40
# File 'lib/rrj/rabbit/connect.rb', line 36

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

#transaction_longObject

Create an transaction with rabbitmq and not close



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

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

#transaction_shortObject

Create an transaction with rabbitmq and close after response is received



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

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