class RubyRabbitmqJanus::Janus::Transactions::Transaction

@author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>

# Manage a transactions

This class work with Janus and send a series of message

Attributes

exclusive[R]
handle[R]
publisher[R]
rabbit[R]
response[R]
session[R]

Public Class Methods

new(session) click to toggle source

Initialize a transaction

@param [Fixnum] session

Use a session identifier for created message
# File lib/rrj/janus/transactions/transaction.rb, line 17
def initialize(session)
  @rabbit = RubyRabbitmqJanus::Rabbit::Connect.new
  @session = session
  @publisher = @exclusive = nil
end

Private Instance Methods

choose_queue() click to toggle source
# File lib/rrj/janus/transactions/transaction.rb, line 28
def choose_queue
  chan = @rabbit.channel
  @publisher = if @exclusive
                 ::Log.debug \
                   'Choose an queue Exclusive : ampq.gen-xxx'
                 Rabbit::Publisher::Exclusive.new(chan, '')
               else
                 ::Log.debug \
                   'Choose an queue non Exclusive : to-janus'
                 Rabbit::Publisher::NonExclusive.new(chan)
               end
end
read_response(publish) click to toggle source
# File lib/rrj/janus/transactions/transaction.rb, line 47
def read_response(publish)
  @exclusive ? publish : {}
end
send_a_message() { || ... } click to toggle source
# File lib/rrj/janus/transactions/transaction.rb, line 41
def send_a_message
  ::Log.info 'Publish a message ...'
  response = read_response(@publisher.publish(yield))
  Janus::Responses::Standard.new(response)
end