Module: Karafka::Pro::Routing::Features::Patterns::ConsumerGroup
- Defined in:
- lib/karafka/pro/routing/features/patterns/consumer_group.rb
Overview
Expansion of the consumer groups routing component to work with patterns
Instance Method Summary collapse
- #initialize(*args) ⇒ Object
-
#pattern=(regexp_or_name, regexp = nil, &block) ⇒ Object
Creates the pattern for topic matching with appropriate virtual topic.
-
#patterns ⇒ ::Karafka::Pro::Routing::Features::Patterns::Patterns
Created patterns.
-
#to_h ⇒ Hash
Consumer group with patterns injected.
Instance Method Details
#initialize(*args) ⇒ Object
14 15 16 17 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 14 def initialize(*args) super @patterns = Patterns.new([]) end |
#pattern=(regexp_or_name, regexp = nil, &block) ⇒ Object
Creates the pattern for topic matching with appropriate virtual topic
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 30 def pattern=(regexp_or_name, regexp = nil, &block) # This code allows us to have a nice nameless (automatic-named) patterns that do not # have to be explicitly named. However if someone wants to use names for exclusions # it can be done by providing both if regexp_or_name.is_a?(Regexp) name = nil regexp = regexp_or_name else name = regexp_or_name end pattern = Pattern.new(name, regexp, block) virtual_topic = public_send(:topic=, pattern.name, &block) # Indicate the nature of this topic (matcher) virtual_topic.patterns(active: true, type: :matcher, pattern: pattern) # Pattern subscriptions should never be part of declarative topics definitions # Since they are subscribed by regular expressions, we do not know the target # topics names so we cannot manage them via declaratives virtual_topic.config(active: false) pattern.topic = virtual_topic @patterns << pattern end |
#patterns ⇒ ::Karafka::Pro::Routing::Features::Patterns::Patterns
Returns created patterns.
20 21 22 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 20 def patterns @patterns end |
#to_h ⇒ Hash
Returns consumer group with patterns injected.
54 55 56 57 58 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 54 def to_h super.merge( patterns: patterns.map(&:to_h) ).freeze end |