Class: Karafka::Pro::ActiveJob::Dispatcher

Inherits:
ActiveJob::Dispatcher show all
Defined in:
lib/karafka/pro/active_job/dispatcher.rb

Overview

Pro dispatcher that sends the ActiveJob job to a proper topic based on the queue name and that allows to inject additional options into the producer, effectively allowing for a much better and more granular control over the dispatch and consumption process.

Instance Method Summary collapse

Instance Method Details

#call(job) ⇒ Object

Parameters:

  • job (ActiveJob::Base)

    job



36
37
38
39
40
41
42
43
44
# File 'lib/karafka/pro/active_job/dispatcher.rb', line 36

def call(job)
  ::Karafka.producer.public_send(
    fetch_option(job, :dispatch_method, DEFAULTS),
    dispatch_details(job).merge!(
      topic: job.queue_name,
      payload: ::ActiveSupport::JSON.encode(job.serialize)
    )
  )
end