Important
You are viewing documentation for an older version of Confluent Platform. For the latest, click here.
Code Examples¶
You can find Streams code examples in the Apache Kafka and Confluent GitHub repositories.
The Confluent Streams examples are located here. These examples demonstrate the use of Java 8 lambda expressions (which simplify the code significantly), show how to read/write Avro data, and how to implement end-to-end integration tests using embedded Kafka clusters.
The Apache Kafka Streams examples are located at https://github.com/apache/kafka/streams/examples/. These examples demonstrate the use of the Kafka Streams DSL and the low-level Processor API, including typed and untyped examples.
Getting started examples¶
Java¶
With lambda expressions for Java 8+:
- WordCountLambdaExample
- AnomalyDetectionLambdaExample
- GlobalKTablesExample
- MapFunctionLambdaExample
- PageViewRegionLambdaExample
- UserRegionLambdaExample
- WikipediaFeedAvroLambdaExample
- ApplicationResetExample
- SessionWindowsExample
- SumLambdaExample
- TopArticlesLambdaExample
Without lambda expressions for Java 7+:
Interactive queries examples¶
Since Confluent Platform 3.1+ and Kafka 0.10.1+, it is possible to query state stores created via the Kafka Streams DSL and the Processor API. Please refer to Interactive Queries for further information.
End-to-end application examples¶
These demo applications use embedded instances of Kafka, ZooKeeper, and Confluent Schema Registry. They are implemented as integration tests.
Java¶
With lambda expressions for Java 8+:
- WordCountLambdaIntegrationTest
- FanoutLambdaIntegrationTest
- GenericAvroIntegrationTest
- GlobalKTablesExampleTest
- HandlingCorruptedInputRecordsIntegrationTest
- MapFunctionLambdaIntegrationTest
- MixAndMatchLambdaIntegrationTest – how to mix the DSL and the Processor API
- SpecificAvroIntegrationTest
- StateStoresInTheDSLIntegrationTest – how to use state stores in the DSL
- StreamToStreamJoinIntegrationTest
- StreamToTableJoinIntegrationTest
- TableToTableJoinIntegrationTest
- UserCountsPerRegionLambdaIntegrationTest
- ApplicationResetIntegrationTest
- EventDeduplicationLambdaIntegrationTest
- SumLambdaIntegrationTest
- TopArticlesLambdaExampleTest
Without lambda expressions for Java 7:
Scala¶
- StreamToTableJoinScalaIntegrationTest
- ProbabilisticCountingScalaIntegrationTest - demonstrates how to probabilistically count items in an input stream by implementing a custom state store that is backed by a Count-Min Sketch data structure
- GenericAvroScalaIntegrationTest
- SpecificAvroScalaIntegrationTest
- WordCountScalaIntegrationTest
Event-Driven Microservice example¶
Java¶
The Event-Driven Microservice example implements an Orders Service that provides a REST interface to POST and GET orders. Posting an order creates an event in Kafka, which is picked up by three different validation engines: a Fraud Service, an Inventory Service, and an Order Details Service. These services validate the order in parallel, emitting a PASS or FAIL based on whether each validation succeeds.