Sha256: 4c395eba3e300ee9dcf65bc8ae9b59599d7fa6b4cedfda7a3a0f13738ee81537

Contents?: true

Size: 1.01 KB

Versions: 26

Compression:

Stored size: 1.01 KB

Contents

class Freddy
  module MessageHandlerAdapters
    class Factory
      def initialize(producer)
        @no_op_handler = NoOpHandler.new
        @request_handler = RequestHandler.new(producer)
      end

      def for(delivery)
        if delivery.type == 'request'
          @request_handler
        else
          @no_op_handler
        end
      end
    end

    class NoOpHandler
      def success(*)
        # NOP
      end

      def error(*)
        # NOP
      end
    end

    class RequestHandler
      def initialize(producer)
        @producer = producer
      end

      def success(delivery, response)
        send_response(delivery, response, type: 'success')
      end

      def error(delivery, response)
        send_response(delivery, response, type: 'error')
      end

      private

      def send_response(delivery, response, opts = {})
        @producer.produce delivery.reply_to.force_encoding('utf-8'), response, {
          correlation_id: delivery.correlation_id
        }.merge(opts)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
freddy-1.4.1 lib/freddy/message_handler_adapaters.rb
freddy-1.4.0 lib/freddy/message_handler_adapaters.rb
freddy-1.3.3 lib/freddy/message_handler_adapaters.rb
freddy-jruby-1.3.2 lib/freddy/message_handler_adapaters.rb
freddy-1.3.2 lib/freddy/message_handler_adapaters.rb
freddy-1.3.1 lib/freddy/message_handler_adapaters.rb
freddy-1.3.0 lib/freddy/message_handler_adapaters.rb
freddy-1.2.0 lib/freddy/message_handler_adapaters.rb
freddy-1.1.0 lib/freddy/message_handler_adapaters.rb
freddy-1.0.1 lib/freddy/message_handler_adapaters.rb
freddy-jruby-1.0.0 lib/freddy/message_handler_adapaters.rb
freddy-1.0.0 lib/freddy/message_handler_adapaters.rb
freddy-jruby-0.7.2 lib/freddy/message_handler_adapaters.rb
freddy-0.7.2 lib/freddy/message_handler_adapaters.rb
freddy-0.7.1 lib/freddy/message_handler_adapaters.rb
freddy-0.7.0 lib/freddy/message_handler_adapaters.rb
freddy-0.6.3 lib/freddy/message_handler_adapaters.rb
freddy-0.6.2 lib/freddy/message_handler_adapaters.rb
freddy-0.6.1 lib/freddy/message_handler_adapaters.rb
freddy-jruby-0.6.0 lib/freddy/message_handler_adapaters.rb