Movatterモバイル変換


[0]ホーム

URL:


Auto reload of code changes in development

Karafka supports auto-reload of code changes for Ruby on Rails, similar to Puma or Sidekiq.

Due to consumers persistence in Karafka (long-living consumer instances), in order to make it work, you need to turn it on yourself by setting aconsumer_persistence configuration option in thekarafka.rb file tofalse in the development mode:

class KarafkaApp < Karafka::App  setup do |config|    config.kafka = { 'bootstrap.servers': '127.0.0.1:9092' }    config.client_id = 'example_app'    config.concurrency = 2    # Recreate consumers with each batch. This will allow Rails code reload to work in the    # development mode. Otherwise Karafka process would not be aware of code changes    config.consumer_persistence = !Rails.env.development?  endend

Your code changes will be applied after processing of current messages batch.

Keep in mind, though, that there are a couple of limitations to it:

  • Changes in the routing arenot reflected. This would require reconnections and would drastically complicate reloading.
  • Any background work you run outside the Karafka framework but within the process might not be caught in the reloading.
  • If you use in-memory consumer data buffering that spans multiple batches, itwon't work as code reload means re-initializing consumer instances. In cases like that, you will be better off not using the reload mode.

Last modified: 2023-11-03 14:36:20


[8]ページ先頭

©2009-2025 Movatter.jp