Module: Karafka::Extensions::SidekiqTopicAttributes

Defined in:
lib/karafka/extensions/sidekiq_topic_attributes.rb

Overview

Additional Karafka::Routing::Topic methods that are required to work with Sidekiq backend

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Creates attributes writers for worker and interchanger, so they can be overwritten

Parameters:

  • base (Class)

    Karafka::Routing::Topic class



22
23
24
25
# File 'lib/karafka/extensions/sidekiq_topic_attributes.rb', line 22

def self.included(base)
  base.send :attr_writer, :worker
  base.send :attr_writer, :interchanger
end

Instance Method Details

#interchanger#encode, #decode

Returns Interchanger instance (not a class) that we want to use to interchange params between Karafka server and Karafka background job.

Returns:

  • (#encode, #decode)

    Interchanger instance (not a class) that we want to use to interchange params between Karafka server and Karafka background job



16
17
18
# File 'lib/karafka/extensions/sidekiq_topic_attributes.rb', line 16

def interchanger
  @interchanger ||= Karafka::Interchanger.new
end

#workerClass

Note:

If not provided - will be built based on the provided consumer

Returns Class (not an instance) of a worker that should be used to schedule the background job.

Returns:

  • (Class)

    Class (not an instance) of a worker that should be used to schedule the background job



10
11
12
# File 'lib/karafka/extensions/sidekiq_topic_attributes.rb', line 10

def worker
  @worker ||= backend == :sidekiq ? Karafka::Workers::Builder.new(consumer).build : nil
end