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
22 23 24 25 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 22 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 38 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.
28 29 30 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 28 def patterns @patterns end |
#to_h ⇒ Hash
Returns consumer group with patterns injected.
62 63 64 65 66 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 62 def to_h super.merge( patterns: patterns.map(&:to_h) ).freeze end |