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



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/karafka/web/pro/commanding/matcher.rb', line 18

def matches?(message)
  # We operate only on commands. Result and other messages should be ignored
  return false unless message.headers['type'] == 'request'
  # We want to work only with commands that target all processes or our current
  return false unless message.key == '*' || message.key == process_id
  # 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
  return false unless message.payload[:schema_version] == Dispatcher::SCHEMA_VERSION

  true
end