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

Defined in:
lib/karafka/routing/features/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



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

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



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

def active_job?
  active_job.active?
end

#initializeObject

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.



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

def initialize(...)
  super
  @active_job = nil
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



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

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