Giter Club home page Giter Club logo

kafka_playground's Introduction

KafkaPlayground

A Kafka sample project

In here I wanted to show how you can:

  • Produce a message to a Kafka Broker
  • Consume messages from Kafka Broker

I tried to paid attention to ordering guarantee

Get Started

Add the kafka nodes to /hosts file

sudo echo "127.0.0.1	kafka1 kafka2 kafka3" >> /etc/hosts

Start the Kafka cluster (only for development purpose, it will start a cluster with 3 nodes)

docker-compose up

I used the wurstmeister docker images

Test Kafka Setup

I tried to follow the quickstart steps

  1. Enter Kafka
docker exec -it kafka_playground_kafka1_1 /bin/bash
  1. Create a topic
/opt/kafka/bin/kafka-topics.sh --create --topic test --zookeeper zookeeper:2181 --replication-factor 2 --partitions 3
  1. Get the detail about the topic
/opt/kafka/bin/kafka-topics.sh --describe --zookeeper zookeeper:2181 --topic test
  1. Producing messages

I wanted to produce messages for a certain key, so that we can guarantee the order for each kafka partion.

/opt/kafka/bin/kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic test --property "parse.key=true" --property "key.separator=:"

example of a message:

mykey:a message
  1. Consuming messages
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test --from-beginning --property "print.key=true"

Now with Elixir

I am using KafkaEx as Kafka Client.

mix deps.get
iex -S mix
  1. Produce a message
iex> Kafka.produce("test", "my key", "something")
  1. Consume messages
iex> Kafka.consume("test")

Stop one of the node of Kafka to see what happen ๐Ÿ˜ˆ

docker-compose stop kafka2

And continue to produce and consume messages, and then

docker-compose start kafka2

Open Questions โ“

  • How the partition is choosen based on the key of the message?
  • Why I need to speficy the partition when consuming message for a specific topic?
  • How consumers_group works?

kafka_playground's People

Contributors

joebew42 avatar

Watchers

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