An example app using elsa
Install dependencies.
mix deps.get
Start Kafka with divo and divo_kafka.
mix docker.start
At this point, you can write messages to the configured Kafka topic (default let-it-go-topic
) by any means. LetItGo
provides a helper function to make this easy (and demonstrate producer setup).
Drop into an IEx
session running LetItGo
and use LetItGo.write/1
to produce messages. This function will accept a single string or a list of strings.
iex -S mix
LetItGo.write("this is a message")
LetItGo.write(["foo", "bar", "baz"])
Messages will be read from Kafka and written to disk in .output/messages
. New messages overwrite the file, because I'm lazy and it kept the code simpler.
See the LetItGo.Application module documentation for specifics on configuring your application to read from Kafka and handle messages.
See the LetItGo.KafkaWriter module documentation for specifics on configuring your application to write to Kafka.
See the LetItGo.TopicCreator module documentation for specifics on ensuring a topic exists to read from/write to.
By default, LetItGo
assumes you're going to spin up a Kafka cluster in Docker with divo and use a topic named let-it-go-topic
. But these can be overwritten in application configuration. The :kafka
field must be a keyword list with a hostname atom key and an integer port value. The :topic
field must be a string.
# config/config.exs
config :let_it_go,
kafka: [broker_host_name: 9999],
topic: "custom-topic-name"