All Projects → abhirockzz → kafka-streams-example

abhirockzz / kafka-streams-example

Licence: Apache-2.0 license
Kafka Streams based microservice

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to kafka-streams-example

java-jaxrs
OpenTracing Java JAX-RS instrumentation
Stars: ✭ 37 (+48%)
Mutual labels:  jax-rs, jersey
jersey-jwt-springsecurity
Example of REST API with JWT authentication using Spring Boot, Spring Security, Jersey and Jackson.
Stars: ✭ 44 (+76%)
Mutual labels:  jersey
kafka-scala-examples
Examples of Avro, Kafka, Schema Registry, Kafka Streams, Interactive Queries, KSQL, Kafka Connect in Scala
Stars: ✭ 53 (+112%)
Mutual labels:  kafka-streams
spring-rest-2-ts
spring rest 2 ts is typescript generator which produces data model and services in typescript based on Spring MVC annotations. It supports generation for Angular and React
Stars: ✭ 59 (+136%)
Mutual labels:  jax-rs
twitterstream
Twitter Streaming API Example with Kafka Streams in Scala
Stars: ✭ 49 (+96%)
Mutual labels:  kafka-streams
open-stream-processing-benchmark
This repository contains the code base for the Open Stream Processing Benchmark.
Stars: ✭ 37 (+48%)
Mutual labels:  kafka-streams
example-kafkastreams
Kafka Streams DSL vs Processor API
Stars: ✭ 16 (-36%)
Mutual labels:  kafka-streams
aws-lambda-servlet
AWS Lambda adapter for Java's Servlets (and Jersey in particular, JAX-RS implementation)
Stars: ✭ 24 (-4%)
Mutual labels:  jersey
spring-boot-demo
使用spring-boot的简单代码库,方便以后copy代码
Stars: ✭ 24 (-4%)
Mutual labels:  jersey
rest.vertx
A JAX-RS like annotation processor for vert.x verticals and more
Stars: ✭ 138 (+452%)
Mutual labels:  jax-rs
football-events
Event-Driven microservices with Kafka Streams
Stars: ✭ 57 (+128%)
Mutual labels:  kafka-streams
jax-rs-pac4j
Security library for JAX-RS and Jersey
Stars: ✭ 48 (+92%)
Mutual labels:  jax-rs
kstreams-des-demo
Kafka Streams demo project containing Derivative Events, the Processor Api and Wall-clock examples
Stars: ✭ 24 (-4%)
Mutual labels:  kafka-streams
kafka-cluster-infra
Terraform and Ansible to install a Kafka Cluster
Stars: ✭ 37 (+48%)
Mutual labels:  kafka-streams
e-shop
Sample Spring Cloud microservices e-shop.
Stars: ✭ 48 (+92%)
Mutual labels:  kafka-streams
fdp-modelserver
An umbrella project for multiple implementations of model serving
Stars: ✭ 47 (+88%)
Mutual labels:  kafka-streams
kafka-serde-scala
Implicitly converts typeclass encoders to kafka Serializer, Deserializer, Serde.
Stars: ✭ 52 (+108%)
Mutual labels:  kafka-streams
formula1-telemetry-kafka
No description or website provided.
Stars: ✭ 99 (+296%)
Mutual labels:  kafka-streams
redisks
Redis Kafka Streams State Store
Stars: ✭ 37 (+48%)
Mutual labels:  kafka-streams
kotlin-kafka-and-kafka-streams-examples
Kafka with KafkaReactor and Kafka Streams Examples in Kotlin
Stars: ✭ 33 (+32%)
Mutual labels:  kafka-streams

This is an example of a Kafka Streams based microservice (packaged in form of an Uber JAR). The scenario is simple

Basics

  • A producer application continuously emits CPU usage metrics into a Kafka topic (cpu-metrics-topic)
  • The consumer is a Kafka Streams application which uses the Processor (low level) Kafka Streams API to calculate the Cumulative Moving Average of the CPU metrics of each machine
  • Consumers can be horizontally scaled - the processing work is distributed amongst many nodes and the process is elastic and flexible thanks to Kafka Streams (and the fact that it leverages Kafka for fault tolerance etc.)
  • Each instance has its own (local) state for the calculated average. A custom REST API has been (using Jersey JAX-RS implementation) to tap into this state and provide a unified view of the entire system (moving averages of CPU usage of all machines)

Setup

This project has two modules

To try things out...

  • Start Kafka broker. Configure num.partitions in Kafka broker server.properties file to 5 (to experiment with this application)
  • Build producer & consumer application - browse to the respective directory and execute mvn clean install
  • Trigger producer application - java -jar kafka-cpu-metrics-producer.jar. It will start emitting records to Kafka
  • Start one instance of consumer application - java -jar kafka-cpu-metrics-consumer-1.0.jar -DKAFKA_CLUSTER=<kafka host:port> (defaults to localhost:9092 if not provided). Note the auto-selected port. It will start calculating the moving average of machine CPU metrics
  • Access the metrics on this instance - http://localhost:<inst1_port>/metrics
  • Start another instance of consumer application - java -jar kafka-cpu-metrics-consumer-1.0.jar -DKAFKA_CLUSTER=<kafka host:port> (note the auto-selected port), wait for a few seconds - the load will now be distributed amongst the two instances. Access the metrics http://localhost:<inst2_port>/metrics - you will see the metrics (JSON/XML payload) for all the machines as well as the instance on which the Cumulative Moving Average has been calculated

sample output - https://gist.github.com/abhirockzz/48e89873ae23c93d0a5cc721c87cc536

  • You can also search for metrics for a specific machine ID http://localhost:<any_app_port>/metrics/<machineID>

sample output - https://gist.github.com/abhirockzz/2ca2297fbc9aec269d31707f61b4c45e

You can keep increasing the number of instances such that they are less than or equal to the number of partitions of your Kafka topic

Having more instances than number of partitions is not going to have any effect on parallelism and that instance will be inactive until any of the existing instance is stopped

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].