Giter VIP home page Giter VIP logo

kafka-streaming-consumer's Introduction

This is an example use of Kafka streaming API in Java where multiple instance of this program monitors for new message in a specific topic in kafka and handles. The messages publiched to (produced) the Kafka topic is distributed across multiple consumers running as part of the instance. Same message is not consumed by more than one consumers because the consumers are defined as part of same consumer group in the application.yaml.

This also demonstrates it can be used alternative to the Google Cloud Pub/Sub's push subscription mode.

Steps

  1. Install and run Apache Kafka

    brew install kafka
    cd /usr/local/Cellar/kafka/1.1.0/bin
    zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties 
    

    Troubleshooting - sometimes server.properties may have to contain the localhost listener explicitly i.e. listeners=PLAINTEXT://localhost:9092

  2. run multiple instances of this program with following (it will always start with a random port to avoid conflict if you are running in the same machine.

    mvn spring-boot:run
    
  3. Publish the message using command line or API

    Command Line

    $ /usr/local/Cellar/kafka/1.1.0/bin/kafka-console-producer --broker-list localhost:9092 --topic greetings
    

    API

    $ curl http://localhost:<PORT>/greetings?message=hello
    

    The <PORT> can be found from any of the consoles while running the program.

  4. Verify (from the consol log) that the messeges are going to only one of the instance of the program not all. For debugging you can also consume from the command line as follows to see all the messages that are getting published.

    $ /usr/local/Cellar/kafka/1.1.0/bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic greetings --from-beginning
    

Reference - https://dzone.com/articles/kafka-streams-more-than-just-dumb-storage

kafka-streaming-consumer's People

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.