Sha256: 96fca9571185093582a53dad463d99a5e9c47cbef747063093e372afe10a88ad

Contents?: true

Size: 994 Bytes

Versions: 33

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

33 entries across 33 versions & 1 rubygems

Version Path
rimless-1.13.2 lib/rimless/base_consumer.rb
rimless-1.13.1 lib/rimless/base_consumer.rb
rimless-1.13.0 lib/rimless/base_consumer.rb
rimless-1.12.0 lib/rimless/base_consumer.rb
rimless-1.11.0 lib/rimless/base_consumer.rb
rimless-1.10.2 lib/rimless/base_consumer.rb
rimless-1.10.1 lib/rimless/base_consumer.rb
rimless-1.10.0 lib/rimless/base_consumer.rb
rimless-1.9.0 lib/rimless/base_consumer.rb
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