Class: RubyRabbitmqJanus::Janus::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/rrj/janus/transactions/transaction.rb

Overview

This class work with janus and send a series of message :reek:TooManyInstanceVariables

Author:

Direct Known Subclasses

TransactionSession

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Transaction

Initialize an transaction



10
11
12
13
14
15
16
# File 'lib/rrj/janus/transactions/transaction.rb', line 10

def initialize(session)
  @rabbit = Rabbit::Connect.new
  @session = session
  @response = @handle = @publish = nil
rescue => error
  raise Errors::JanusTransaction, error
end

Instance Attribute Details

#handleObject (readonly, private)

Returns the value of attribute handle.



28
29
30
# File 'lib/rrj/janus/transactions/transaction.rb', line 28

def handle
  @handle
end

#publishObject (readonly, private)

Returns the value of attribute publish.



28
29
30
# File 'lib/rrj/janus/transactions/transaction.rb', line 28

def publish
  @publish
end

#rabbitObject (readonly, private)

Returns the value of attribute rabbit.



28
29
30
# File 'lib/rrj/janus/transactions/transaction.rb', line 28

def rabbit
  @rabbit
end

#responseObject (readonly, private)

Returns the value of attribute response.



28
29
30
# File 'lib/rrj/janus/transactions/transaction.rb', line 28

def response
  @response
end

#sessionObject (readonly, private)

Returns the value of attribute session.



28
29
30
# File 'lib/rrj/janus/transactions/transaction.rb', line 28

def session
  @session
end

Instance Method Details

#choose_queue(exclusive = false) ⇒ Object (private)

determine queue used :reek:ControlParameter and :reek:BooleanParameter



32
33
34
35
36
37
38
39
40
41
# File 'lib/rrj/janus/transactions/transaction.rb', line 32

def choose_queue(exclusive = false)
  chan = @rabbit.channel
  @publish = if exclusive
               Tools::Log.instance.debug 'Choose an queue non Exclusive : to-janus'
               Rabbit::Publisher::PublishNonExclusive.new(chan)
             else
               Tools::Log.instance.debug 'Choose an queue Exclusive : ampq.gen-xxx'
               Rabbit::Publisher::PublishExclusive.new(chan, '')
             end
end

#connect(exclusive) ⇒ Object

Opening a short transaction with rabbitmq and close when is ending



19
20
21
22
23
24
# File 'lib/rrj/janus/transactions/transaction.rb', line 19

def connect(exclusive)
  @rabbit.transaction_short do
    choose_queue(exclusive)
    send_a_message { yield }
  end
end

#create_handleObject (private)

Associate handle to transaction



49
50
51
52
# File 'lib/rrj/janus/transactions/transaction.rb', line 49

def create_handle
  msg = Janus::Message.new('base::attach', 'session_id' => @session)
  @handle = send_a_message { msg }.sender
end

#send_a_messageObject (private)

Send a message to queue



44
45
46
# File 'lib/rrj/janus/transactions/transaction.rb', line 44

def send_a_message
  Janus::Response.new(@publish.send_a_message(yield))
end