Class: Karafka::Web::Pro::Commanding::Matcher
- Inherits:
-
Object
- Object
- Karafka::Web::Pro::Commanding::Matcher
- 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.
The matcher uses a set of sub-matchers, each responsible for checking a specific criterion. Matchers have two methods:
apply?- returns true if the matcher's criterion is present in the messagematches?- returns true if the criterion matches (only checked if apply? is true)
Matcher classes are auto-loaded from the Matchers namespace and sorted by priority. Required matchers (MessageType, SchemaVersion) have lower priority and are checked first.
Class Method Summary collapse
-
.matcher_classes ⇒ Array<Class>
All matcher classes sorted by priority.
Instance Method Summary collapse
-
#matches?(message) ⇒ Boolean
Is this message dedicated to current process and is actionable.
Class Method Details
.matcher_classes ⇒ Array<Class>
Returns all matcher classes sorted by priority.
51 52 53 54 55 56 57 58 |
# File 'lib/karafka/web/pro/commanding/matcher.rb', line 51 def matcher_classes @matcher_classes ||= Matchers .constants .map { |name| Matchers.const_get(name) } .select { |klass| klass.is_a?(Class) && klass < Matchers::Base } .sort_by(&:priority) .freeze end |
Instance Method Details
#matches?(message) ⇒ Boolean
Returns is this message dedicated to current process and is actionable.
63 64 65 66 67 68 69 70 71 |
# File 'lib/karafka/web/pro/commanding/matcher.rb', line 63 def matches?() self .class .matcher_classes .lazy .map { |klass| klass.new() } .select(&:apply?) .all?(&:matches?) end |