.. _streams_code_examples: Code Examples ------------- You can find Streams code examples in the Apache Kafka and Confluent GitHub repositories. The Confluent Kafka Streams examples are located :cp-examples:`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 :kafka-file:`https://github.com/apache/kafka/streams/examples/|streams/examples/src/main/java/org/apache/kafka/streams/examples`. These examples demonstrate the use of the :ref:`Kafka Streams DSL ` and the :ref:`low-level Processor API `, including typed and untyped examples. .. contents:: :local: Getting started examples """""""""""""""""""""""" """" Java """" With lambda expressions for Java 8+: * :cp-examples:`WordCountLambdaExample|src/main/java/io/confluent/examples/streams/WordCountLambdaExample.java` * :cp-examples:`AnomalyDetectionLambdaExample|src/main/java/io/confluent/examples/streams/AnomalyDetectionLambdaExample.java` * :cp-examples:`GlobalKTablesExample|src/main/java/io/confluent/examples/streams/GlobalKTablesExample.java` * :cp-examples:`MapFunctionLambdaExample|src/main/java/io/confluent/examples/streams/MapFunctionLambdaExample.java` * :cp-examples:`PageViewRegionLambdaExample|src/main/java/io/confluent/examples/streams/PageViewRegionLambdaExample.java` * :cp-examples:`UserRegionLambdaExample|src/main/java/io/confluent/examples/streams/UserRegionLambdaExample.java` * :cp-examples:`WikipediaFeedAvroLambdaExample|src/main/java/io/confluent/examples/streams/WikipediaFeedAvroLambdaExample.java` Without lambda expressions for Java 7+: * :cp-examples:`PageViewRegionExample|src/main/java/io/confluent/examples/streams/PageViewRegionExample.java` * :cp-examples:`WikipediaFeedAvroExample|src/main/java/io/confluent/examples/streams/WikipediaFeedAvroExample.java` """"" Scala """"" * :cp-examples:`MapFunctionScalaExample|src/main/scala/io/confluent/examples/streams/MapFunctionScalaExample.scala` Security examples """"""""""""""""" """"""""""""""""""""""""" Java programming language """"""""""""""""""""""""" Without lambda expressions for Java 7: * :cp-examples:`SecureKafkaStreamsExample|src/main/java/io/confluent/examples/streams/SecureKafkaStreamsExample.java` Interactive queries examples """""""""""""""""""""""""""" Since Confluent Platform 3.1+ and Kafka 0.10.1+, it is possible to query state stores created via the :ref:`Kafka Streams DSL ` and the :ref:`Processor API `. Please refer to :ref:`Interactive Queries` for further information. """" Java """" With lambda expressions for Java 8+: * :cp-examples:`WordCountInteractiveQueriesExample|src/main/java/io/confluent/examples/streams/interactivequeries/WordCountInteractiveQueriesExample.java` * :cp-examples:`KafkaMusicExample|src/main/java/io/confluent/examples/streams/interactivequeries/kafkamusic/KafkaMusicExample.java` 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+: * :cp-examples:`WordCountLambdaIntegrationTest|src/test/java/io/confluent/examples/streams/WordCountLambdaIntegrationTest.java` * :cp-examples:`FanoutLambdaIntegrationTest|src/test/java/io/confluent/examples/streams/FanoutLambdaIntegrationTest.java` * :cp-examples:`GenericAvroIntegrationTest|src/test/java/io/confluent/examples/streams/GenericAvroIntegrationTest.java` * :cp-examples:`GlobalKTablesExampleTest|src/test/java/io/confluent/examples/streams/GlobalKTablesExampleTest.java` * :cp-examples:`HandlingCorruptedInputRecordsIntegrationTest|src/test/java/io/confluent/examples/streams/HandlingCorruptedInputRecordsIntegrationTest.java` * :cp-examples:`MapFunctionLambdaIntegrationTest|src/test/java/io/confluent/examples/streams/MapFunctionLambdaIntegrationTest.java` * :cp-examples:`MixAndMatchLambdaIntegrationTest|src/test/java/io/confluent/examples/streams/MixAndMatchLambdaIntegrationTest.java` -- how to mix the DSL and the Processor API * :cp-examples:`SpecificAvroIntegrationTest|src/test/java/io/confluent/examples/streams/SpecificAvroIntegrationTest.java` * :cp-examples:`StateStoresInTheDSLIntegrationTest|src/test/java/io/confluent/examples/streams/StateStoresInTheDSLIntegrationTest.java` -- how to use state stores in the DSL * :cp-examples:`StreamToStreamJoinIntegrationTest|src/test/java/io/confluent/examples/streams/StreamToStreamJoinIntegrationTest.java` * :cp-examples:`StreamToTableJoinIntegrationTest|src/test/java/io/confluent/examples/streams/StreamToTableJoinIntegrationTest.java` * :cp-examples:`TableToTableJoinIntegrationTest|src/test/java/io/confluent/examples/streams/TableToTableJoinIntegrationTest.java` * :cp-examples:`UserCountsPerRegionLambdaIntegrationTest|src/test/java/io/confluent/examples/streams/UserCountsPerRegionLambdaIntegrationTest.java` Without lambda expressions for Java 7: * :cp-examples:`PassThroughIntegrationTest|src/test/java/io/confluent/examples/streams/PassThroughIntegrationTest.java` """"" Scala """"" * :cp-examples:`StreamToTableJoinScalaIntegrationTest|src/test/scala/io/confluent/examples/streams/StreamToTableJoinScalaIntegrationTest.scala` * :cp-examples:`ProbabilisticCountingScalaIntegrationTest|src/test/scala/io/confluent/examples/streams/ProbabilisticCountingScalaIntegrationTest.scala` - 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