Module: Karafka::Pro::Routing::Features::Swarm::Topic
- Defined in:
- lib/karafka/pro/routing/features/swarm/topic.rb
Overview
Topic swarm API extensions
Instance Method Summary collapse
-
#active? ⇒ Boolean
Should this topic be active.
-
#initialize ⇒ Object
This method calls the parent class initializer and then sets up the extra instance variable to nil.
-
#swarm(nodes: (0...Karafka::App.config.swarm.nodes)) ⇒ Object
Allows defining swarm routing topic settings.
-
#swarm? ⇒ true
Swarm setup is always true.
-
#to_h ⇒ Hash
Topic with all its native configuration options plus swarm.
Instance Method Details
#active? ⇒ Boolean
Returns should this topic be active. In the context of swarm it is only active when swarm routing setup does not limit nodes on which it should operate.
59 60 61 62 63 64 65 |
# File 'lib/karafka/pro/routing/features/swarm/topic.rb', line 59 def active? node = Karafka::App.config.swarm.node return super unless node super && swarm.nodes.include?(node.id) end |
#initialize ⇒ Object
This method calls the parent class initializer and then sets up the extra instance variable to nil. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.
17 18 19 20 |
# File 'lib/karafka/pro/routing/features/swarm/topic.rb', line 17 def initialize(...) super @swarm = nil end |
#swarm(nodes: (0...Karafka::App.config.swarm.nodes)) ⇒ Object
Allows defining swarm routing topic settings
48 49 50 |
# File 'lib/karafka/pro/routing/features/swarm/topic.rb', line 48 def swarm(nodes: (0...Karafka::App.config.swarm.nodes)) @swarm ||= Config.new(active: true, nodes: nodes) end |
#swarm? ⇒ true
Returns swarm setup is always true. May not be in use but is active.
53 54 55 |
# File 'lib/karafka/pro/routing/features/swarm/topic.rb', line 53 def swarm? swarm.active? end |
#to_h ⇒ Hash
Returns topic with all its native configuration options plus swarm.
68 69 70 71 72 |
# File 'lib/karafka/pro/routing/features/swarm/topic.rb', line 68 def to_h super.merge( swarm: swarm.to_h ).freeze end |