At Zendesk we’ve invested heavily in Kafka. We’ve authored the Maxwell MySQL change capture application and the ruby-kafka client library.
Today we’d like to announce a new open source project: Racecar. Racecar makes it dead easy to write, configure, test, and run Kafka consumers in Ruby, and integrates nicely into Rails applications. It sacrifices some flexibility in exchange for simpler operation — if you need more tuning, you can always use ruby-kafka directly.
If you’re using Rails, getting started is easy; just add this to your Gemfile:
gem "racecar"Now, add a consumer class that will receive messages from your Kafka topic. Start by executing the following:
$ rails generate racecar:consumer helloThis should create a file at app/consumers/hello_consumer.rb that looks like this:
Let’s test things out! Assuming you’re running Kafka on your local machine, execute the following command:
$ racecar HelloConsumerThe consumer will start running, waiting for messages to appear on the topic some-topic. Let’s write a message to this topic in order to test that things actually work. In another terminal window, execute the following:
$ racecarctl produce --value "hello!" --topic some-topicYou should now see the greeting printed by your consumer!