Coder Social home page Coder Social logo

jeremyloye / cs3219_taskd_kafkacluster Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eugeneyl/cs3219_taskd_kafkacluster

0.0 0.0 0.0 91 KB

Create a 3 node Apache Kafka cluster using Docker that demonstrates the Pub-Sub messaging, with a Zookeeper ensemble created to manage the Kafka cluster.

cs3219_taskd_kafkacluster's Introduction

CS3219 OTOT Task D

Task

Create a 3 node Apache Kafka cluster using Docker that demonstrates the Pub-Sub messaging, with a Zookeeper ensemble created to manage the Kafka cluster.

Server setup

There will be 3 kafka nodes and zookeeper nodes deployed across 3 different servers. Each of the server will run a single zookeeper node and a kafka node.

Dependencies

For each of the server, run the following command to download the required dependencies for the setup and testing of the kafka clusters.

#Linux
sudo apt-get install docker docker-compose kafkacat

Docker-compose is used to set up the containers. Kafkacat is a command line client utility tool to interact with kafka.

Setup Instructions

  1. Fork and clone this repo to each of your 3 different machines.
  2. Navigate to the repo directory.
  3. Edit the docker-compose.yml file and add the IP addresses of each of your servers.
  4. Start up the zookeeper node and kafka node using the docker-compose.yml file.
#For server 1
docker-compose up -d zookeeper1 kafka1

#For server 2
docker-compose up -d zookeeper2 kafka2

#For server 3
docker-compose up -d zookeeper3 kafka3

Using the Kafka Clusters

  1. Create a topic. Use a replication-factor of more than 1 for the fail safe mechanism to work.
docker run --rm ches/kafka kafka-topics.sh --create --topic {topic_name} --replication-factor 3 --partitions 1 --zookeeper {any_server_ipadd}
  1. Check if the topic has been successfully created.
kafkacat -L -b {any_server_ipadd}:9092
  1. Once the topic is created, you can start sending messages. In order to do so, you need to have at least 1 publisher and 1 consumer. This can be done across different servers, or using the same server but through 2 terminals.
# Creating a publisher
kafkacat -P -b {any_server_ipadd}:9092 -t {topic_name}

# Creating a consumer
kafkacat -C -b {any_server_ipadd}:9092 -t {topic_name}
  1. You can now type messages in the publisher terminal and see it appear in the consumer(s) terminal.

publisher

consumer

Failure Management of Master Node

For each of the topic, there will be a leader nominated.

leader

For topics that have a replication-factor of more than 1, when the leader server is down (this can be simulated by stopping the docker container), one of the remaining kafka brokers in will take over as the leader.

leader_change

In the first screenshot, the leader of the topic sendmessage was broker 1005. After the docker container for that broker was stopped, broker 1003 took over as the leader.

cs3219_taskd_kafkacluster's People

Contributors

eugeneyl 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.