Class: Karafka::Web::Pro::Commanding::Matchers::PartitionId

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

Overview

Note:

This matcher only checks for partition_id presence across all topics. For topic-specific partition matching, use this in combination with the Topic matcher.

Matcher that checks if the current process has a specific partition assigned. Uses the Karafka assignments tracker to check actual current assignments. This is an optional matcher that only applies when partition_id is specified.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Karafka::Web::Pro::Commanding::Matchers::Base

Instance Method Details

#apply?Boolean

Returns true if partition_id criterion is specified in matchers.

Returns:

  • (Boolean)

    true if partition_id criterion is specified in matchers



45
46
47
# File 'lib/karafka/web/pro/commanding/matchers/partition_id.rb', line 45

def apply?
  !partition_id.nil?
end

#matches?Boolean

Checks if this process has the specified partition assigned (any topic)

Returns:

  • (Boolean)

    true if this process has the partition assigned



52
53
54
55
56
# File 'lib/karafka/web/pro/commanding/matchers/partition_id.rb', line 52

def matches?
  ::Karafka::App.assignments.any? do |_topic, partitions|
    partitions.include?(partition_id)
  end
end