Module: Karafka::Routing::Features::ConsumerGroups::ActiveJob::Topic

Defined in:
lib/karafka/routing/features/consumer_groups/active_job/topic.rb

Overview

Note:

ActiveJob topics do not have per-topic deserializer configuration. The deserializer is configured globally via ‘config.internal.active_job.deserializer` because Rails serializes jobs before dispatching them, requiring a consistent serialization format across all ActiveJob topics. If you need custom serialization (e.g., Avro, Protobuf), configure it once at the application level rather than per-topic.

Topic extensions to be able to check if given topic is ActiveJob topic

Instance Method Summary collapse

Instance Method Details

#active_job(active = false) ⇒ Object

Note:

Since this feature supports only one setting (active), we can use the old API

where the boolean would be an argument

Parameters:

  • active (Boolean) (defaults to: false)

    should this topic be considered one working with ActiveJob



29
30
31
# File 'lib/karafka/routing/features/consumer_groups/active_job/topic.rb', line 29

def active_job(active = false)
  @active_job ||= Config.new(active: active)
end

#active_job?Boolean

Returns is this an ActiveJob topic.

Returns:

  • (Boolean)

    is this an ActiveJob topic



34
35
36
# File 'lib/karafka/routing/features/consumer_groups/active_job/topic.rb', line 34

def active_job?
  active_job.active?
end

#initializeObject

This method sets up the extra instance variable to nil before calling the parent class initializer. The explicit initialization to nil is included as an optimization for Ruby’s object shapes system, which improves memory layout and access performance.



20
21
22
23
# File 'lib/karafka/routing/features/consumer_groups/active_job/topic.rb', line 20

def initialize(...)
  @active_job = nil
  super
end

#to_hHash

Returns topic with all its native configuration options plus active job namespace settings.

Returns:

  • (Hash)

    topic with all its native configuration options plus active job namespace settings



40
41
42
43
44
# File 'lib/karafka/routing/features/consumer_groups/active_job/topic.rb', line 40

def to_h
  super.merge(
    active_job: active_job.to_h
  ).freeze
end