DEV Community

Kiran Mantha
Kiran Mantha

Posted on

13 1

How to setup Kafka locally

I came across 2 reliable ways to setup kafka locally:

Install kafka

Without docker

  • download kafka tar file from official site

  • extract the downloaded tar file and cd to that location

  • run zookeeper through bin/zookeeper-server-start.sh config/zookeeper.properties

  • once zookeeper is up and running, in another terminal execute bin/kafka-server-start.sh config/server.properties to start kafka

  • once kafka is up and running, it need to have one topic before consuming it to emit and read events. for this in a new terminal execute bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092

    this is a one-time action.

  • this will create a topic named quickstart-events

  • to list out all the topics, execute bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

With docker

  • docker-compose.yml:
version: "3.1"

services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"

  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: localhost
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
  • place the above yml file in project root folder and run docker compose up in root folder.
  • this will pull latest zookeeper & kafka packages and run them on their respective ports.

And that's how we can setup kafka locally.

See you in next article,
Kiran 👋 👋

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more