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
31 32 33 34 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 31 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 47 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.
37 38 39 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 37 def patterns @patterns end |
#to_h ⇒ Hash
Returns consumer group with patterns injected.
71 72 73 74 75 |
# File 'lib/karafka/pro/routing/features/patterns/consumer_group.rb', line 71 def to_h super.merge( patterns: patterns.map(&:to_h) ).freeze end |