Sha256: 05413f49097481f2172adb9a1631adf2c3cd2bb35309da08b871cbfff4ff4f3d

Contents?: true

Size: 1.82 KB

Versions: 33

Compression:

Stored size: 1.82 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::PublishExclusive.new(chan, '')
                       else
                         Tools::Log.instance.debug \
                           'Choose an queue non Exclusive : to-janus'
                         Rabbit::Publisher::PublishNonExclusive.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

33 entries across 33 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.5.1.pre.217 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.1 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.1.pre.215 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.0 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.0.pre.213 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.0.pre.210 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.5.0.pre.209 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.4.0.pre.208 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.1.pre.201 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.1.pre.198 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0.pre.197 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0.pre.196 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0.pre.194 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0.pre.192 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.3.0.pre.170 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.2.2 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.2.1 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.2.1.pre.181 lib/rrj/janus/transactions/transaction.rb
ruby_rabbitmq_janus-2.2.1.pre.180 lib/rrj/janus/transactions/transaction.rb