Sha256: 96fca9571185093582a53dad463d99a5e9c47cbef747063093e372afe10a88ad

Contents?: true

Size: 994 Bytes

Versions: 24

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

module Rimless
  # The base consumer where all Apache Kafka messages will be processed. It
  # comes with some simple conventions to keep the actual application code
  # simple to use.
  class BaseConsumer < ::Karafka::BaseConsumer
    # A generic message consuming handler which resolves the message event name
    # to an actual method. All message data (top-level keys) is passed down to
    # the event method as symbol arguments.
    def consume
      # We ignore events we do not handle by definition
      send(event, **arguments) if respond_to? event
    end

    # Prepare the message payload as event method arguments.
    #
    # @return [Hash{Symbol => Mixed}] the event method arguments
    def arguments
      params.payload.except(:event)
    end

    # A shortcut to fetch the event name from the Kafka message.
    #
    # @return [Symbol] the event name of the current message
    def event
      params.payload[:event].to_sym
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rimless-1.8.0 lib/rimless/base_consumer.rb
rimless-1.7.7 lib/rimless/base_consumer.rb
rimless-1.7.6 lib/rimless/base_consumer.rb
rimless-1.7.5 lib/rimless/base_consumer.rb
rimless-1.7.4 lib/rimless/base_consumer.rb
rimless-1.7.3 lib/rimless/base_consumer.rb
rimless-1.7.2 lib/rimless/base_consumer.rb
rimless-1.7.1 lib/rimless/base_consumer.rb
rimless-1.7.0 lib/rimless/base_consumer.rb
rimless-1.6.0 lib/rimless/base_consumer.rb
rimless-1.5.1 lib/rimless/base_consumer.rb
rimless-1.5.0 lib/rimless/base_consumer.rb
rimless-1.4.2 lib/rimless/base_consumer.rb
rimless-1.4.1 lib/rimless/base_consumer.rb
rimless-1.4.0 lib/rimless/base_consumer.rb
rimless-1.3.0 lib/rimless/base_consumer.rb
rimless-1.2.0 lib/rimless/base_consumer.rb
rimless-1.1.1 lib/rimless/base_consumer.rb
rimless-1.1.0 lib/rimless/base_consumer.rb
rimless-1.0.4 lib/rimless/base_consumer.rb