Code Monkey home page Code Monkey logo

apache-kafka-book-examples's Introduction

Fixed and updated code examples from the book "Apache Kafka"

  • Updated to Apache Kafka 0.8.1.1
  • Configuration optimized for usage on Windows machines
  • Windows batch scripts fixed (taken from https://github.com/HCanber/kafka by @HCanber)
  • Code examples repaired and refactored

Initial Setup

  1. Download and install Apache Kafka 0.8.1.1 (I used the recommended Scala 2.9.2 binary)
  2. Copy the scripts from /bat into /bin/windows of your Kafka installation folder (overwrite existing scripts)
  3. Copy the property files from /config into /config of your Kafka installation folder (overwrite existing files)

Simple Java Producer (Chapter 5, Page 35ff.)

  1. Open command line in your Kafka installation folder
  2. Launch Zookeeper with .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
  3. Open a second command line in your Kafka installation folder
  4. Launch single Kafka broker: .\bin\windows\kafka-server-start.bat .\config\server.properties
  5. Open a third command line in your Kafka installation folder
  6. Create a topic: .\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
  7. Start a console consumer for that topic: .\bin\windows\kafka-console-consumer.bat --zookeeper localhost:2181 --topic test --from-beginning
  8. From a fourth command line or your IDE run SimpleProducer with topic and message as arguments: java SimpleProducer test HelloKafka
  9. The message HelloKafka should appear in the console consumer's log

Java Producer with Message Partitioning (Chapter 5, Page 37ff.)

  1. Open command line in your Kafka installation folder
  2. Launch Zookeeper with .\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
  3. Open a second command line in your Kafka installation folder
  4. Launch first Kafka broker: .\bin\windows\kafka-server-start.bat .\config\server-1.properties
  5. Open a third command line in your Kafka installation folder
  6. Launch second Kafka broker: .\bin\windows\kafka-server-start.bat .\config\server-2.properties
  7. Open a fourth command line in your Kafka installation folder
  8. Create a topic: .\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 2 --partitions 4 --topic kafkatest
  9. Start a console consumer for that topic: .\bin\windows\kafka-console-consumer.bat --zookeeper localhost:2181 --topic kafkatest --from-beginning
  10. From a fifth command line or your IDE run MultiBrokerProducer with topic as argument: java MultiBrokerProducer kafkatest
  11. Ten messages starting with This message is for key - (...) should appear in the console consumer's log

Simple High Level Java Consumer (Chapter 6, Page 47ff.)

  1. Launch multi-broker Kafka cluster and create topic kafkatest as described in step 1-8 of Java Producer with Message Partitioning
  2. From another command line or your IDE run SimpleHLConsumer with topic as argument: java SimpleHLConsumer kafkatest
  3. From another command line or your IDE run MultiBrokerProducer with same topic as argument: java MultiBrokerProducer kafkatest
  4. Ten messages starting with This message is for key - (...) should appear in the log of the SimpleHLConsumer

Multithreaded Consumer for Multipartition Topics (Chapter 6, Page 50ff.)

  1. Launch multi-broker Kafka cluster and create topic kafkatest as described in step 1-8 of Java Producer with Message Partitioning
  2. From another command line or your IDE run MultiThreadHLConsumer with topic and number of threads as argument: java MultiThreadHLConsumer kafkatest 4
  3. From another command line continuously produce messages by running MultiBrokerProducer several times in a row: java MultiBrokerProducer kafkatest (Note: You must start producing messages within 10sec after starting the consumer class, otherwise the consumer will shut down)
  4. Messages starting with Message from thread (...) should appear in the log of the MultiThreadHLConsumer spread among the four threads

apache-kafka-book-examples's People

Contributors

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