This repo contains the source code for the "Building Interactive Query Service" presentation at Current 2022 in Austin, Texas on October 5th 2022.
About the project
The goal of this GitHub repo is to server as a basic reference implementation for building an interactive query service in Kafka Streams. For building your own IQ application you should be able to fork this project and follow the pattern here for adding your own controllers and web page for displaying the results. This project also uses Standby tasks for demonstrating high-availability for Kafka Streams as well as interactive queries.
Dependencies
The project uses the following dependencies
- For the web serving layer the application uses Spring Boot Note that we're only using Spring Boot for providing the dependency injection required to wire up the application - no specific
spring-kafkaorspring-kafka-streamsfunctionality is leveraged like@EnableKafkaStreams - The application is using JQuery for making REST API calls and rendering the results in a dynamic web page found in
- The integration tests use Testcontainers and Junit 5. The integration tests don't use any spring specific testing utilities
Running the application
To run the application you have two options
- COMING SOON: Build an uber jar from the project by running
./gradlew shadowJarthen runjava -jar kafka-streams-iq-app.jarfrom the command line. Note to run more than one instance on the same host, you'll have to set a unique port for each instance using a-Dserver.port=NNNNsetting for each one. - Run from IntelliJ. Again you'll have to set a unique port for running more than one instance using
-Dserver.port=NNNNin theSpring-Bootsection of therun/debugconfiguration settings - To push records through the Kafka Streams application run the TestDataProducer class again from either IntelliJ or a separate command from the command line
java -jar jarFile TestDataProducer - The application.properties file contains the Kafka Streams properties. The configuration class KafkaStreamsAppConfiguration class ingests these properties. For connecting to Confluent Cloud there's the confluent.properties.orig you can also use this file for secure connections to any Kafka cluster. The KafkaStreamsAppConfiguration class is expecting a
confluent.propertiesfile to exist to use for secure connections. To make sure you don't check in any sensitive configs save theconfluent.properties.origfile asconfluent.propertieswhich is set to ignore in the.gitignorefile. - There is a configuration
secure.configsin the application.properties file which is set totrueby default - to disable loading theconfluent.propertiesfile (testing, or on-prem unsecure brokers) set this configuration tofalse
Testing
There is an integration test for both key and range query: InteractiveQueriesIntegrationTest For both tests, they start two Kafka Streams applications, produces some records then asserts both active hosts return results then shuts down one application and asserts that the standby returns query results. The integration tests serve to show an example of testing an IQ application and will also help validate any changes you may make in the application.
NOTE: that the test uses testcontainers and the Kafka image is for M1 macs so if you're on x86 you'll have to adjust the docker image pulled for the test.