zendesk / racecar

Racecar: a simple framework for Kafka consumers in Ruby
Apache License 2.0
480 stars 95 forks source link

Config not loaded automatically for a producer in Rails. #329

Open jcoyne opened 1 year ago

jcoyne commented 1 year ago

If I have a Rails controller that does:

Racecar.produce_sync(...)

it will not get the config loaded from config/racecar.rb or config/racecar.yml

it is only loaded in the CLI (for the consumer): https://github.com/zendesk/racecar/blob/0a7d9592749c3b5479ae340a8633f1491c654a6d/lib/racecar/cli.rb#L27-L31

deepredsky commented 1 year ago

Standalone producer does not seem to load rails config by default. I will look into fixing that. Meanwhile you can load it manually in a rails initializer, something like this

# file config/initializers/racecar.rb
Racecar.config.load_file("config/racecar.yml", ENV["RAILS_ENV"])

Alternatively you could configure racecar directly in the initializer

Racecar.configure do |config|
  config.brokers = 'localhost:9092'
end