Sha256: 19b91299f56378dd2404968b8c4606fac727b6b86f3f79e7e1618184757a1f30

Contents?: true

Size: 1021 Bytes

Versions: 34

Compression:

Stored size: 1021 Bytes

Contents

require 'dry-initializer'
module Messaging
  module Adapters
    class Test
      class Consumer
        include Messaging::Routing
        extend Dry::Initializer

        option :name

        option :logger,   default: -> { Config.logger }
        option :queue,    default: -> { Queue.new }

        def start
          logger.info "Consumer #{name} started"
          @running = true
          process_messages
        ensure
          shutdown
        end

        def stop
          @running = false
          queue << :stop
          logger.info "Consumer #{name} stopping"
        end

        def shutdown
          logger.info "Consumer #{name} stopped"
        end

        private

        def process_messages
          while @running
            message = queue.pop
            logger.info "Consumer #{name} got #{message}"
            break if message == :stop

            RunMiddlewares.call(Config.consumer.middlewares, message) { handle message }
          end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
messaging-4.0.12 lib/messaging/adapters/test/consumer.rb
messaging-4.0.11 lib/messaging/adapters/test/consumer.rb
messaging-4.0.10 lib/messaging/adapters/test/consumer.rb
messaging-4.0.10.pre lib/messaging/adapters/test/consumer.rb
messaging-4.0.9 lib/messaging/adapters/test/consumer.rb
messaging-4.0.8 lib/messaging/adapters/test/consumer.rb
messaging-4.0.7 lib/messaging/adapters/test/consumer.rb
messaging-4.0.6 lib/messaging/adapters/test/consumer.rb
messaging-4.0.5 lib/messaging/adapters/test/consumer.rb
messaging-4.0.4.pre lib/messaging/adapters/test/consumer.rb
messaging-4.0.3.pre lib/messaging/adapters/test/consumer.rb
messaging-4.0.2.pre lib/messaging/adapters/test/consumer.rb
messaging-4.0.1.pre lib/messaging/adapters/test/consumer.rb
messaging-4.0.0.pre lib/messaging/adapters/test/consumer.rb
messaging-3.8.2 lib/messaging/adapters/test/consumer.rb
messaging-3.8.1 lib/messaging/adapters/test/consumer.rb
messaging-3.8.0 lib/messaging/adapters/test/consumer.rb
messaging-3.7.3 lib/messaging/adapters/test/consumer.rb
messaging-3.7.2 lib/messaging/adapters/test/consumer.rb
messaging-3.7.1 lib/messaging/adapters/test/consumer.rb