Class: Karafka::Web::Pro::Commanding::Matchers::Base

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

Overview

Base class for all sub-matchers.

Sub-matchers receive the full message and extract the relevant data they need. This provides a consistent API across all matchers.

Matchers have two methods:

  • ‘apply?` - returns true if this matcher’s criterion is present and should be checked

  • ‘matches?` - returns true if the criterion matches (only called if apply? is true)

Required matchers (MessageType, SchemaVersion) always apply. Optional matchers (ProcessId, ConsumerGroupId, Topic) decide if they should be applied

based on the message details

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Base

Returns a new instance of Base.

Parameters:

  • message (Karafka::Messages::Message)

    the command message to match against



67
68
69
# File 'lib/karafka/web/pro/commanding/matchers/base.rb', line 67

def initialize(message)
  @message = message
end

Class Attribute Details

.priorityInteger

Priority determines the order in which matchers are checked. Lower values are checked first. Required matchers should have lower priority.

Returns:

  • (Integer)

    matcher priority (default: 100)



61
62
63
# File 'lib/karafka/web/pro/commanding/matchers/base.rb', line 61

def priority
  @priority || 100
end

Instance Method Details

#apply?Boolean

Checks if this matcher should be applied to the message. Override in subclasses for optional matchers.

Returns:

  • (Boolean)

    true if this matcher should check the message



75
76
77
# File 'lib/karafka/web/pro/commanding/matchers/base.rb', line 75

def apply?
  true
end

#matches?Boolean

Checks if the criterion is satisfied. Only called when apply? returns true.

Returns:

  • (Boolean)

    true if matches

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/karafka/web/pro/commanding/matchers/base.rb', line 83

def matches?
  raise NotImplementedError, "Implement in a subclass"
end