Sha256: 9a9bc31ab40d9e3386cbe59279062e0f89e1f1fa2a76289d0d0adb4bfc316ad9

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

# :reek:TooManyStatements

module RubyRabbitmqJanus
  module Rabbit
    module Listener
      # Base for listeners
      class Base < RubyRabbitmqJanus::Rabbit::BaseEvent
        # Define an publisher
        #
        # @param [String] rabbit Information connection to RabbitMQ server
        def initialize(rabbit)
          super()
          @rabbit = rabbit.channel
          subscribe_queue
        rescue
          raise Errors::Rabbit::Listener::Base::Initialize
        end

        # Listen a queue and return a body response
        def listen_events
          semaphore.wait
          response = nil
          lock.synchronize do
            response = responses.shift
          end
          yield response.event, response
        rescue
          raise Errors::Rabbit::Listener::Base::ListenEvents
        end

        private

        attr_accessor :rabbit, :responses

        def binding
          @rabbit.direct('amq.direct')
        end

        def opts_subs
          { block: false, manual_ack: true, arguments: { 'x-priority': 2 } }
        end

        def info_subscribe(info, _prop, payload)
          ::Log.debug info
          ::Log.info '[X] Message reading'
          ::Log.info payload
        end
      end
    end
  end
end

require 'rrj/rabbit/listener/from'
require 'rrj/rabbit/listener/from_admin'
require 'rrj/rabbit/listener/janus_instance'

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.7.2.pre.316 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.315 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.314 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.312 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.310 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.309 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.308 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.307 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.306 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.305 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.302 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.297 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.296 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.286 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.285 lib/rrj/rabbit/listener/base.rb
ruby_rabbitmq_janus-2.7.2.pre.284 lib/rrj/rabbit/listener/base.rb