Sha256: 0004cd88e1b00729778b4c90e41899dd2dd10f3c66ef8da874caf5e59d03c536

Contents?: true

Size: 1.21 KB

Versions: 25

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    module Transactions
      # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
      #
      # # Manage a transaction
      #
      # Manage a transaction with message if contains a session identifier
      class Session < Transaction
        # Initialize a transaction with handle
        #
        # @param [Fixnum] session
        #   Use a session identifier for created message
        def initialize(exclusive, session)
          super(session)
          @exclusive = exclusive
        end

        # Opening a short transaction with rabbitmq and close when is ending
        #
        # @yield Send a message to Janus
        def connect
          rabbit.transaction_short do
            choose_queue
            yield
          end
        end

        # Publish a message to "standard" RabbitMQ queue.
        def publish_message(type, options = {})
          msg = Janus::Messages::Standard.new(type, opts.merge!(options))
          response = read_response(publisher.publish(msg))
          Janus::Responses::Standard.new(response)
        end

        private

        def opts
          { 'session_id' => session }
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-3.0.0 lib/rrj/janus/transactions/session.rb
ruby_rabbitmq_janus-3.0.0.pre.387 lib/rrj/janus/transactions/session.rb
ruby_rabbitmq_janus-3.0.0.pre.385 lib/rrj/janus/transactions/session.rb
ruby_rabbitmq_janus-3.0.0.pre.384 lib/rrj/janus/transactions/session.rb
ruby_rabbitmq_janus-3.0.0.pre.382 lib/rrj/janus/transactions/session.rb