Sha256: 0515b0e6714ad2147ba0e90c96ff604b39d54c58423ea1e3505f75c31e1cbcf5

Contents?: true

Size: 1.38 KB

Versions: 36

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Janus
    module Transactions
      # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>

      # This class work with janus and send a series of message
      class Admin < Session
        def initialize(session)
          super(true, session)
        rescue
          raise Errors::Janus::TransactionAdmin::Initialize
        end

        # Begin connection with RabbitMQ
        def connect
          rabbit.transaction_short do
            @publisher = Rabbit::Publisher::PublisherAdmin.new(rabbit.channel)
            yield
          end
        rescue
          raise Errors::Janus::TransactionAdmin::Connect
        end

        # Write a message in queue in RabbitMQ
        def publish_message(type, options = {})
          msg = Janus::Messages::Admin.new(type, opts.merge(options))
          response = read_response(publisher.publish(msg))
          Janus::Responses::Admin.new(response)
        rescue
          raise Errors::Janus::TransactionAdmin::PublishMessage
        end

        private

        def send_a_message
          Janus::Responses::Admin.new(publisher.publish(yield))
        end

        def admin_secret
          Tools::Config.instance.options['rabbit']['admin_pass']
        end

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

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.3.1.pre.201 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.1.pre.198 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0.pre.197 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0.pre.196 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0.pre.194 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0.pre.192 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.3.0.pre.170 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.2 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.1 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.1.pre.181 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.1.pre.180 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.179 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.177 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.173 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.170 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.168 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.167 lib/rrj/janus/transactions/admin.rb
ruby_rabbitmq_janus-2.2.0.pre.166 lib/rrj/janus/transactions/admin.rb