Sha256: a2f569a3b2dec4f0ec4421e3c51176e28921139017f442b35bae00bb6b4ccb7a

Contents?: true

Size: 1.8 KB

Versions: 11

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    # Define an module for manipulate messages between apps and Janus
    module Transactions
      # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
      #
      # # Manage a transactions
      #
      # This class work with Janus and send a series of message
      class Transaction
        # Initialize a transaction
        #
        # @param [Fixnum] session
        #   Use a session identifier for created message
        def initialize(session)
          @rabbit = RubyRabbitmqJanus::Rabbit::Connect.new
          @session = session
          @publisher = @exclusive = nil
        rescue
          raise Errors::Janus::Transaction::Initialize
        end

        private

        attr_reader :rabbit, :session, :response, :handle, :publisher,
                    :exclusive

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

        def send_a_message
          Tools::Log.instance.info 'Publish a message ...'
          response = read_response(@publisher.publish(yield))
          Janus::Responses::Standard.new(response)
        end

        def read_response(publish)
          @exclusive ? publish : {}
        end
      end
    end
  end
end

require 'rrj/janus/transactions/session'
require 'rrj/janus/transactions/handle'
require 'rrj/janus/transactions/admin'

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.6.0.pre.247 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.246 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.244 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.240 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.239 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.238 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.233 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.229 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.228 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.227 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.6.0.pre.226 lib/rrj/janus/transactions/transaction.rb