Class: Karafka::Pro::Routing::Features::Patterns::Pattern
- Inherits:
 - 
      Object
      
        
- Object
 - Karafka::Pro::Routing::Features::Patterns::Pattern
 
 
- Defined in:
 - lib/karafka/pro/routing/features/patterns/pattern.rb
 
Overview
Karafka topic pattern object It represents a topic that is not yet materialized and that contains a name that is a regexp and not a “real” value. Underneath we define a dynamic topic, that is not active, that can be a subject to normal flow validations, etc.
Instance Attribute Summary collapse
- 
  
    
      #config  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Config for real-topic configuration during injection.
 - 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Each pattern has its own “topic” that we use as a routing reference that we define with non-existing topic for the routing to correctly pick it up for operations Virtual topic name for initial subscription.
 - 
  
    
      #regexp  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Pattern regexp.
 - 
  
    
      #topic  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Associated created virtual topic reference.
 
Instance Method Summary collapse
- 
  
    
      #initialize(name, regexp, config)  ⇒ Pattern 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Pattern.
 - 
  
    
      #regexp_string  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
Defined regexp representation as a string that is compatible with librdkafka expectations.
 - 
  
    
      #to_h  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Hash representation of this routing pattern.
 
Constructor Details
#initialize(name, regexp, config) ⇒ Pattern
Returns a new instance of Pattern.
      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/pattern.rb', line 42 def initialize(name, regexp, config) @regexp = regexp # This name is also used as the underlying matcher topic name # # It can be used provided by the user in case user wants to use exclusions of topics # or we can generate it if irrelevant. # # We generate it based on the regexp so within the same consumer group they are # always unique (checked by topic validations) # # This will not prevent users from creating a different regexps matching the same # topic but this minimizes simple mistakes # # This sub-part of sh1 should be unique enough and short-enough to use it here digest = Digest::SHA1.hexdigest(safe_regexp.source)[8..16] @name = name ? name.to_s : "karafka-pattern-#{digest}" @config = config end  | 
  
Instance Attribute Details
#config ⇒ Object (readonly)
Config for real-topic configuration during injection
      36 37 38  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 36 def config @config end  | 
  
#name ⇒ Object (readonly)
Each pattern has its own “topic” that we use as a routing reference that we define with non-existing topic for the routing to correctly pick it up for operations Virtual topic name for initial subscription
      30 31 32  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 30 def name @name end  | 
  
#regexp ⇒ Object
Pattern regexp
      25 26 27  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 25 def regexp @regexp end  | 
  
#topic ⇒ Object
Associated created virtual topic reference
      33 34 35  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 33 def topic @topic end  | 
  
Instance Method Details
#regexp_string ⇒ String
Returns defined regexp representation as a string that is compatible with librdkafka expectations. We use it as a subscription name for initial patterns subscription start.
      64 65 66  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 64 def regexp_string "^#{safe_regexp.source}" end  | 
  
#to_h ⇒ Hash
Returns hash representation of this routing pattern.
      69 70 71 72 73 74 75  | 
    
      # File 'lib/karafka/pro/routing/features/patterns/pattern.rb', line 69 def to_h { regexp: regexp, name: name, regexp_string: regexp_string }.freeze end  |