This repo contains the sample application for the Developing event-driven applications with Kafka and Docker guide on Docker Docs. While this project is written primarily in Node, the focus is on launching and using Kafka in development and the Kafka-related pieces can easily be adapted into any other language.
Notice: This sample repo is intended to support the guide mentioned above. As such, the application code is purposely kept simple to keep the focus on the guide's content and should not be considered production ready.
This project contains the following components:
- app/ - the main "app" of the project. It simply listens to events on a Kafka topic and logs them
- dev/publisher/ - a simple project intended to make it easy to publish messages into the topic the main app is listening to
-
Clone the project.
git clone https://github.com/dockersamples/kafka-development-node.git
-
Navigate into the project.
cd kafka-development-node
To launch this project, you have two options - run the app natively (without containers) or run everything in containers.
To run the app natively, you will need to start a Kafka instance. Then, you can start the various apps:
-
Start Kafka by running the following command:
docker run -d --name=kafka -p 9092:9092 apache/kafka-native
-
Navigate into the
app
directory, install dependencies, and then start the app.cd app yarn install yarn dev
-
To run the test publisher app, open another terminal and from the root of the project, run the following:
cd dev/publisher yarn install yarn dev
Once it's running, you can open the app at http://localhost:3000. As you fill out the form, you should see the events be logged in the app console output.
To run everything out of containers, you can leverage the Docker Compose configuration in the project.
-
Start Compose by running the following command:
docker compose up
Within a few moments, everything will be up and running. The following URLs will open the various services:
- http://localhost:3000 - the publisher app to send test messages
- http://localhost:8080 - the Kafbat UI web app to interact with the cluster
Since this project is intended to support a specific use case guide, contributions are limited to bug fixes or security issues. If you have a question, feel free to open an issue!