Sha256: 565a734e61052c50ffb5b0e90bef163070dc69e55933220fd7fbe9710ab682cb

Contents?: true

Size: 1.8 KB

Versions: 34

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
                         ::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

        def send_a_message
          ::Log.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'
require 'rrj/janus/transactions/rspec'

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-3.0.0.pre.336 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-3.0.0.pre.335 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-3.0.0.pre.334 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-3.0.0.pre.330 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-3.0.0.pre.328 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-3.0.0.pre.327 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.322 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.320 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.319 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.318 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.317 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.316 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.315 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.314 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.312 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.310 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.309 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.308 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.7.2.pre.307 lib/rrj/janus/transactions/transaction.rb