Skip to content

Instantly share code, notes, and snippets.

@KiranMantha
Created March 7, 2024 06:53
Show Gist options
  • Save KiranMantha/28ba3894768ad937315b094bc1d1060a to your computer and use it in GitHub Desktop.
Save KiranMantha/28ba3894768ad937315b094bc1d1060a to your computer and use it in GitHub Desktop.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment