Karafka is a framework used to simplify Apache Kafka based Ruby applications development.
Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort.
This repository was created for a sample application that uses a web api and also listens and writes to Apache Kafka topics.
Defined on karafka.rb, this app assumes you have Kafka running on 127.0.0.1:9092
.
In this file, it's also defined a consumer group for the app named default_group
with two topics (with consumers and responders) example
and response
.
Api configuration and a sample endpoint is defined on api.rb.
A simple GET endpoint /frank-says
that is responsible for publising a message using a Responder.
Are the ones responsible for writing messages to a given Kafka topic. They are:
- Responders::Foobar, used on the sinatra sample endpoint to send a message to the
example
topic. - Responders::Example, used by the
Consumers::Example
(defined on karafka config file), responding the consumer's message to theresponse
topic.
Are the ones responsable for listening to Kafka topics. They are:
- Consumers::Example, that listens to the topic
example
(defined on karafka config file), logs the consumed message and responds to theresponse
topic using Responders::Example (also defined on karafka config file). - Consumers::Response, that listens to the topic
response
(defined on karafka config file) and logs the consumed message.
- Run
karafka server
on your terminal to start the Karafka server. - Run
bundle exec ruby api.rb
on another tab of your terminal to start Sinatra.