Class: Karafka::Pro::Routing::Features::Multiplexing

Inherits:
Base show all
Defined in:
lib/karafka/pro/routing/features/multiplexing.rb,
lib/karafka/pro/routing/features/multiplexing/proxy.rb,
lib/karafka/pro/routing/features/multiplexing/config.rb,
lib/karafka/pro/routing/features/multiplexing/contracts/topic.rb,
lib/karafka/pro/routing/features/multiplexing/subscription_group.rb,
lib/karafka/pro/routing/features/multiplexing/subscription_groups_builder.rb,
lib/karafka/pro/routing/features/multiplexing/patches/contracts/consumer_group.rb

Overview

Multiplexing allows for creating multiple subscription groups for the same topic inside of the same subscription group allowing for better parallelism with limited number of processes

Defined Under Namespace

Modules: Contracts, Patches, Proxy, SubscriptionGroup, SubscriptionGroupsBuilder Classes: Config

Class Method Summary collapse

Methods inherited from Routing::Features::Base

activate, load_all, post_setup_all, pre_setup_all

Class Method Details

.post_setup(_config) ⇒ Object

If needed installs the needed listener and initializes tracker

Parameters:

  • _config (Karafka::Core::Configurable::Node)

    app config



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/karafka/pro/routing/features/multiplexing.rb', line 36

def post_setup(_config)
  ::Karafka::App.monitor.subscribe('app.running') do
    # Do not install the manager and listener to control multiplexing unless there is
    # multiplexing enabled and it is dynamic.
    # We only need to control multiplexing when it is in a dynamic state
    next unless ::Karafka::App
                .subscription_groups
                .values
                .flat_map(&:itself)
                .any? { |sg| sg.multiplexing? && sg.multiplexing.dynamic? }

    # Subscribe for events and possibility to manage via the Pro connection manager
    # that supports multiplexing
    ::Karafka.monitor.subscribe(
      ::Karafka::Pro::Connection::Multiplexing::Listener.new
    )
  end
end

.pre_setup(_config) ⇒ Object

Parameters:

  • _config (Karafka::Core::Configurable::Node)

    app config node



26
27
28
29
30
31
# File 'lib/karafka/pro/routing/features/multiplexing.rb', line 26

def pre_setup(_config)
  # Make sure we use proper unique validator for topics definitions
  ::Karafka::Contracts::ConsumerGroup.singleton_class.prepend(
    Patches::Contracts::ConsumerGroup
  )
end