Class: Karafka::Web::Pro::Commanding::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/pro/commanding/matcher.rb

Overview

Matcher that makes a decision whether a given command message should be applied/executed within the context of the current consumer process.

Since we use the assign, each process listens to this topic and receives messages with commands targeting all the processes, this is why it needs to be filtered.

Instance Method Summary collapse

Instance Method Details

#matches?(message) ⇒ Boolean

Returns is this message dedicated to current process and is actionable.

Parameters:

  • message (Karafka::Messages::Message)

    message with command

Returns:

  • (Boolean)

    is this message dedicated to current process and is actionable



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/karafka/web/pro/commanding/matcher.rb', line 26

def matches?(message)
  matches = true

  # We want to work only with commands that target all processes or our current
  matches = false unless message.key == '*' || message.key == process_id
  # We operate only on commands. Result messages should be ignored
  matches = false unless message.payload[:type] == 'command'
  # Ignore messages that have different schema. This can happen in the middle of
  # upgrades of the framework. We ignore this not to risk compatibility issues
  matches = false unless message.payload[:schema_version] == Dispatcher::SCHEMA_VERSION

  matches
end