MCPcopy Index your code
hub / github.com/confluentinc/kafka-streams-examples

github.com/confluentinc/kafka-streams-examples @v8.4.0-2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v8.4.0-2 ↗ · + Follow
687 symbols 2,158 edges 116 files 127 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Kafka Streams Examples

[!NOTE] This repo is replaced with Confluent Tutorials for Apache Kafka. We still "keep the lights on", but we don't improve existing examples any longer, nor do we add new example.

This project contains code examples that demonstrate how to implement real-time applications and event-driven microservices using the Streams API of Apache Kafka aka Kafka Streams.

For more information take a look at the latest Confluent documentation on the Kafka Streams API, notably the Developer Guide


Table of Contents


Available examples

This repository has several branches to help you find the correct code examples for the version of Apache Kafka and/or Confluent Platform that you are using. See Version Compatibility Matrix below for details.

There are three kinds of examples:

  • Examples under src/main/: These examples are short and concise. Also, you can interactively test-drive these examples, e.g. against a local Kafka cluster. If you want to actually run these examples, then you must first install and run Apache Kafka and friends, which we describe in section Packaging and running the examples. Each example also states its exact requirements and instructions at the very top.
  • Examples under src/test/: These examples should test applications under src/main/. Unit Tests with TopologyTestDriver test the stream logic without external system dependencies. The integration tests use an embedded Kafka clusters, feed input data to them (using the standard Kafka producer client), process the data using Kafka Streams, and finally read and verify the output results (using the standard Kafka consumer client). These examples are also a good starting point to learn how to implement your own end-to-end integration tests.
  • Ready-to-run Docker Examples: These examples are already built and containerized.

Examples: Runnable Applications

Additional examples may be found under src/main/.

Application Name Concepts used Java 8+ Java 7+ Scala
WordCount DSL, aggregation, stateful Java 8+ example Scala Example
MapFunction DSL, stateless transformations, map() Java 8+ example Scala Example
SessionWindows Sessionization of user events, user behavior analysis Java 7+ example
GlobalKTable join() between KStream and GlobalKTable Java 8+ example
GlobalStore "join" between KStream and GlobalStore Java 8+ example
PageViewRegion join() between KStream and KTable Java 8+ example Java 7+ example
PageViewRegionGenericAvro Working with data in Generic Avro format Java 8+ example Java 7+ example
WikipediaFeedSpecificAvro Working with data in Specific Avro format Java 8+ example Java 7+ example
SecureKafkaStreams Secure, encryption, client authentication Java 7+ example
Sum DSL, stateful transformations, reduce() Java 8+ example
WordCountInteractiveQueries Interactive Queries, REST, RPC Java 8+ example
KafkaMusic Interactive Queries, State Stores, REST API Java 8+ example
ApplicationReset Application Reset Tool kafka-streams-application-reset Java 8+ example
Microservice Microservice ecosystem, state stores, dynamic routing, joins, filtering, branching, stateful operations Java 8+ example

Examples: Unit Tests

The stream processing of Kafka Streams can be unit tested with the TopologyTestDriver from the org.apache.kafka:kafka-streams-test-utils artifact. The test driver allows you to write sample input into your processing topology and validate its output.

See the documentation at Testing Streams Code.

Examples: Integration Tests

We also provide several integration tests, which demonstrate end-to-end data pipelines. Here, we spawn embedded Kafka clusters and the Confluent Schema Registry, feed input data to them (using the standard Kafka producer client), process the data using Kafka Streams, and finally read and verify the output results (using the standard Kafka consumer client).

Additional examples may be found under src/test/.

Tip: Run mvn test to launch the tests.

Integration Test Name Concepts used Java 8+ Java 7+ Scala
WordCount DSL, aggregation, stateful Java 8+ Example Scala Example
WordCountInteractiveQueries Interactive Queries, REST, RPC Java 7+ Example
Aggregate DSL, groupBy(), aggregate() Java 8+ Example Scala Example
CustomStreamTableJoin DSL, Processor API, Transformers Java 8+ Example
EventDeduplication DSL, Processor API, Transformers Java 8+ Example
GlobalKTable DSL, global state Java 7+ Example
GlobalStore DSL, global state, Transformers Java 7+ Example
HandlingCorruptedInputRecords DSL, flatMap() Java 8+ Example
KafkaMusic (Interactive Queries) Interactive Queries, State Stores, REST API Java 7+ Example
MapFunction DSL, stateless transformations, map() Java 8+ Example
MixAndMatch DSL + Processor API Integrating DSL and Processor API Java 8+ Example
PassThrough DSL, stream(), to() Java 7+ Example
PoisonPill DSL, flatMap() Java 8+ Example
ProbabilisticCounting*** DSL, Processor API, custom state stores Scala Example
Reduce (Concatenate) DSL, groupByKey(), reduce() Java 8+ Example Scala Example
SessionWindows DSL, windowed aggregation, sessionization Java 7+ Example
StatesStoresDSL DSL, Processor API, Transformers Java 8+ Example
StreamToStreamJoin DSL, join() between KStream and KStream Java 7+ Example
StreamToTableJoin DSL, join() between KStream and KTable Java 7+ Example Scala Example
Sum DSL, aggregation, stateful, reduce() Java 8+ Example
TableToTableJoin DSL, join() between KTable and KTable Java 7+ Example
UserCountsPerRegion DSL, aggregation, stateful, count() Java 8+ Example
ValidateStateWithInteractiveQueries Interactive Queries for validating state Java 8+ Example
GenericAvro Working with data in Generic Avro format Java 7+ Example Scala Example
SpecificAvro Working with data in Specific Avro format Java 7+ Example Scala Example

***demonstrates how to probabilistically count items in an input stream by implementing a custom state store (CMSStore) that is backed by a Count-Min Sketch data structure (with the CMS implementation of Twitter Algebird)

Docker Example: Kafka Music demo application

This containerized example launches:

  • Confluent's Kafka Music demo application for the Kafka Streams API, which makes use of [Interactive Queries](http://docs.confluent.io/

Extension points exported contracts — how you extend this code

Service (Interface)
(no doc) [15 implementers]
src/main/java/io/confluent/examples/streams/microservices/Service.java

Core symbols most depended-on inside this repo

start
called by 59
src/main/java/io/confluent/examples/streams/microservices/Service.java
id
called by 55
src/main/java/io/confluent/examples/streams/microservices/domain/beans/OrderId.java
getName
called by 42
src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/SongBean.java
name
called by 38
src/main/java/io/confluent/examples/streams/microservices/domain/Schemas.java
valueSerde
called by 35
src/main/java/io/confluent/examples/streams/microservices/domain/Schemas.java
keySerde
called by 33
src/main/java/io/confluent/examples/streams/microservices/domain/Schemas.java
getId
called by 31
src/main/java/io/confluent/examples/streams/microservices/domain/beans/OrderBean.java
add
called by 25
src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/KafkaMusicExample.java

Shape

Method 548
Class 136
Interface 2
Function 1

Languages

Java98%
Python2%

Modules by API surface

src/test/java/io/confluent/examples/streams/IntegrationTestUtils.java23 symbols
src/main/java/io/confluent/examples/streams/microservices/OrdersService.java23 symbols
src/test/java/io/confluent/examples/streams/microservices/util/MicroserviceTestUtils.java19 symbols
src/test/java/io/confluent/examples/streams/kafka/EmbeddedSingleNodeKafkaCluster.java18 symbols
src/main/java/io/confluent/examples/streams/microservices/util/MicroserviceUtils.java18 symbols
src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/KafkaMusicExample.java15 symbols
test/test_kafka_streams_examples.py14 symbols
src/main/java/io/confluent/examples/streams/microservices/domain/beans/OrderBean.java14 symbols
src/main/java/io/confluent/examples/streams/microservices/EmailService.java14 symbols
src/main/java/io/confluent/examples/streams/interactivequeries/WordCountInteractiveQueriesRestService.java14 symbols
src/test/java/io/confluent/examples/streams/CustomStreamTableJoinIntegrationTest.java13 symbols
src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/SongPlayCountBean.java13 symbols

For agents

$ claude mcp add kafka-streams-examples \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page