Class: Rimless::BaseConsumer

Inherits:
Karafka::BaseConsumer
  • Object
show all
Defined in:
lib/rimless/base_consumer.rb

Overview

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.

Direct Known Subclasses

ApplicationConsumer

Instance Method Summary collapse

Instance Method Details

#argumentsHash{Symbol => Mixed}

Prepare the message payload as event method arguments.

Returns:

  • (Hash{Symbol => Mixed})

    the event method arguments



19
20
21
# File 'lib/rimless/base_consumer.rb', line 19

def arguments
  params.payload.except(:event)
end

#consumeObject

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.



11
12
13
14
# File 'lib/rimless/base_consumer.rb', line 11

def consume
  # We ignore events we do not handle by definition
  send(event, **arguments) if respond_to? event
end

#eventSymbol

A shortcut to fetch the event name from the Kafka message.

Returns:

  • (Symbol)

    the event name of the current message



26
27
28
# File 'lib/rimless/base_consumer.rb', line 26

def event
  params.payload[:event].to_sym
end