GithubHelp home page GithubHelp logo

neginkheirmand / kafka-cheatsheet Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 148 KB

This repository contains a simple Apache Kafka project demonstrating the setup of a Kafka cluster using Docker Compose, along with Python scripts for a Kafka producer and consumer.

Python 100.00%

kafka-cheatsheet's Introduction

Description

This repository contains a simple Apache Kafka project demonstrating the setup of a Kafka cluster using Docker Compose, along with Python scripts for a Kafka producer and consumer.

Contents

  • docker-compose.yml: Docker Compose configuration to set up a Kafka cluster with multiple brokers and ZooKeeper instances.
  • producer.py: A Python script implementing a Kafka producer that sends messages to a specified Kafka topic.
  • consumer.py: A Python script implementing a Kafka consumer that reads messages from a specified Kafka topic.

Features

  • Kafka Cluster Setup: Easily spin up a Kafka cluster using Docker Compose.
  • Python Producer: Script to produce messages to Kafka topics.
  • Python Consumer: Script to consume messages from Kafka topics.

How to Use

1- Start the Kafka Cluster:

docker-compose up -d

1.5- create a topic with a preferred number of partitions:

docker exec -it <kafka_container_id> bash
kafka-topics --create --topic mytopic --partitions <n> --replication-factor 2 --bootstrap-server localhost:9092

is the number of partitions you want to be created for the topic "mytopic". <kafka_container_id> is the container_id of any of the 2 brokers. You can get this value by using the command:

docker ps -a

This step can be skipped since the Kafka Python library already creates a topic of the mentioned name with 1 partition by default when such a topic doesn't exist, still, if you want a specific number of partitions, you can use the previous command.

2- Run the Producer:

python producer.py

Run the Consumer:

python consumer.py

Prerequisites:

  • Docker and Docker Compose installed.
  • Python and the kafka library installed.

Commands Cheatsheet:

here

kafka-cheatsheet's People

Contributors

neginkheirmand avatar

Stargazers

 avatar Amirparsa Salmankhah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.