Skip to content

Configuration

Marcos G. Zimmermann edited this page Sep 25, 2025 · 4 revisions

Configuration

Configure Lepus globally via Lepus.configure or Rails Railtie defaults.

Basic

Lepus.configure do |config|
  config.connection_name = "MyApp"
  config.rabbitmq_url = ENV.fetch("RABBITMQ_URL", "amqp://guest:guest@localhost:5672")
end

Options:

  • rabbitmq_url — default ENV["RABBITMQ_URL"] || amqp://guest:guest@localhost:5672
  • connection_name — appears in RabbitMQ connection info
  • recovery_attempts — max network recovery attempts (nil = infinite, default 10)
  • recovery_interval — seconds between network recovery attempts (default 5.0)
  • recover_from_connection_close — enable Bunny auto-recovery (default true)
  • consumers_directory — directory to eager load consumers from (default app/consumers)
  • app_executor — Rails executor to wrap async work
  • on_thread_error — Proc called on thread errors
  • process_heartbeat_interval — seconds between heartbeats (default 60)
  • process_alive_threshold — seconds to consider process alive (default 300)
  • logger= — set Lepus.logger

Worker Processes

Lepus.configure do |config|
  config.worker(:default) do |w|
    w.pool_size = 1
    w.pool_timeout = 5.0
    w.before_fork { ActiveRecord::Base.clear_all_connections! }
    w.after_fork  { ActiveRecord::Base.establish_connection }
  end
  config.worker(:datasync, pool_size: 1, pool_timeout: 5.0)
end
  • Worker attributes: pool_size, pool_timeout, before_fork, after_fork.
  • Each worker has its own connection pool (Bunny::Session connections).
  • Each consumer subscription gets a dedicated channel from the worker's pool.

Consumers assign themselves with worker: { name:, threads: } in their configure call.

Producers Connection Pool

Lepus.configure do |config|
  config.producer(pool_size: 2, pool_timeout: 10.0)
  # or
  config.producer { |c| c.pool_size = 2; c.pool_timeout = 10.0 }
end

Note: The producer pool_size represents Bunny connections (Bunny::Session), not channels. Bunny’s channel pooling is efficient; a single connection usually suffices.

Rails Integration

When using Rails, the Railtie sets sensible defaults:

  • app.executor as app_executor
  • on_thread_error reports via Rails.error when available, otherwise logs
  • Log subscriber attaches to :lepus events

Clone this wiki locally