Show explicit use of serdes, use latest API, fix compiler warnings
*/
package io.confluent.examples.streams;
-import io.confluent.examples.streams.kafka.EmbeddedSingleNodeKafkaCluster;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
-import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;
@@ -27,16 +25,19 @@ import org.apache.kafka.streams.KeyValue;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.JoinWindows;
+import org.apache.kafka.streams.kstream.Joined;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.test.TestUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
+
+import io.confluent.examples.streams.kafka.EmbeddedSingleNodeKafkaCluster;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +56,7 @@ public class StreamToStreamJoinIntegrationTest {
private static final String outputTopic = "output-topic";
@BeforeClass
- public static void startKafkaCluster() throws Exception {
+ public static void startKafkaCluster() {
CLUSTER.createTopic(adImpressionsTopic);
CLUSTER.createTopic(adClicksTopic);
CLUSTER.createTopic(outputTopic);
@@ -89,8 +90,6 @@ public class StreamToStreamJoinIntegrationTest {
//
// Step 1: Configure and start the processor topology.
//
- final Serde<String> stringSerde = Serdes.String();
-
final Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "stream-stream-join-lambda-integration-test");
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
@@ -115,7 +114,15 @@ public class StreamToStreamJoinIntegrationTest {
incidents,
(impressionValue, clickValue) -> impressionValue + "/" + clickValue,
// KStream-KStream joins are always windowed joins, hence we must provide a join window.
- JoinWindows.of(TimeUnit.SECONDS.toMillis(5))
+ JoinWindows.of(Duration.ofSeconds(5)),
+ // In this specific example, we don't need to define join serdes explicitly because the key, left value, and
+ // right value are all of type String, which matches our default serdes configured for the application. However,
+ // we want to showcase the use of `Joined.with(...)` in case your code needs a different type setup.
+ Joined.with(
+ Serdes.String(), /* key */
+ Serdes.String(), /* left value */
+ Serdes.String() /* right value */
+ )
);
// Write the results to the output topic.
