remove empty module
This commit is contained in:
parent
3e41f10f7f
commit
7871c67031
@ -1,5 +1,9 @@
|
|||||||
package com.baeldung.kafkastreams;
|
package com.baeldung.kafkastreams;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -18,59 +22,57 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class KafkaStreamsLiveTest {
|
public class KafkaStreamsLiveTest {
|
||||||
private String bootstrapServers = "localhost:9092";
|
private String bootstrapServers = "localhost:9092";
|
||||||
|
private Path stateDirectory;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("it needs to have kafka broker running on local")
|
@Ignore("it needs to have kafka broker running on local")
|
||||||
public void shouldTestKafkaStreams() throws InterruptedException {
|
public void shouldTestKafkaStreams() throws InterruptedException {
|
||||||
//given
|
// given
|
||||||
String inputTopic = "inputTopic";
|
String inputTopic = "inputTopic";
|
||||||
|
|
||||||
Properties streamsConfiguration = new Properties();
|
Properties streamsConfiguration = new Properties();
|
||||||
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "wordcount-live-test");
|
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "wordcount-live-test");
|
||||||
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||||
streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
|
streamsConfiguration.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String()
|
||||||
streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
|
.getClass()
|
||||||
|
.getName());
|
||||||
|
streamsConfiguration.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String()
|
||||||
|
.getClass()
|
||||||
|
.getName());
|
||||||
streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 1000);
|
streamsConfiguration.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 1000);
|
||||||
streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
streamsConfiguration.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
|
||||||
// Use a temporary directory for storing state, which will be automatically removed after the test.
|
|
||||||
// streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getAbsolutePath());
|
|
||||||
|
|
||||||
/*
|
// Use a temporary directory for storing state, which will be automatically removed after the test.
|
||||||
* final StreamsBuilder builder = new StreamsBuilder();
|
try {
|
||||||
KStream<String, String> textLines = builder.stream(wordCountTopic,
|
this.stateDirectory = Files.createTempDirectory("kafka-streams");
|
||||||
Consumed.with(Serdes.String(), Serdes.String()));
|
streamsConfiguration.put(StreamsConfig.STATE_DIR_CONFIG, this.stateDirectory.toAbsolutePath()
|
||||||
|
.toString());
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new UncheckedIOException("Cannot create temporary directory", e);
|
||||||
|
}
|
||||||
|
|
||||||
KTable<String, Long> wordCounts = textLines
|
// when
|
||||||
.flatMapValues(value -> Arrays.asList(value.toLowerCase(Locale.ROOT)
|
|
||||||
.split("\\W+")))
|
|
||||||
.groupBy((key, word) -> word)
|
|
||||||
.count(Materialized.<String, Long, KeyValueStore<Bytes, byte[]>> as("counts-store"));
|
|
||||||
*/
|
|
||||||
//when
|
|
||||||
final StreamsBuilder builder = new StreamsBuilder();
|
final StreamsBuilder builder = new StreamsBuilder();
|
||||||
KStream<String, String> textLines = builder.stream(inputTopic);
|
KStream<String, String> textLines = builder.stream(inputTopic);
|
||||||
Pattern pattern = Pattern.compile("\\W+", Pattern.UNICODE_CHARACTER_CLASS);
|
Pattern pattern = Pattern.compile("\\W+", Pattern.UNICODE_CHARACTER_CLASS);
|
||||||
|
|
||||||
KTable<String, Long> wordCounts = textLines
|
KTable<String, Long> wordCounts = textLines.flatMapValues(value -> Arrays.asList(pattern.split(value.toLowerCase())))
|
||||||
.flatMapValues(value -> Arrays.asList(pattern.split(value.toLowerCase())))
|
.groupBy((key, word) -> word)
|
||||||
.groupBy((key, word) -> word)
|
.count();
|
||||||
.count();
|
|
||||||
|
|
||||||
wordCounts.toStream().foreach((word, count) -> System.out.println("word: " + word + " -> " + count));
|
wordCounts.toStream()
|
||||||
|
.foreach((word, count) -> System.out.println("word: " + word + " -> " + count));
|
||||||
|
|
||||||
String outputTopic = "outputTopic";
|
String outputTopic = "outputTopic";
|
||||||
//final Serde<String> stringSerde = Serdes.String();
|
|
||||||
//final Serde<Long> longSerde = Serdes.Long();
|
wordCounts.toStream()
|
||||||
//wordCounts.toStream().to(stringSerde, longSerde, outputTopic);
|
.to(outputTopic, Produced.with(Serdes.String(), Serdes.Long()));
|
||||||
|
|
||||||
wordCounts.toStream().to("outputTopic",
|
|
||||||
Produced.with(Serdes.String(), Serdes.Long()));
|
|
||||||
|
|
||||||
final Topology topology = builder.build();
|
final Topology topology = builder.build();
|
||||||
KafkaStreams streams = new KafkaStreams(topology, streamsConfiguration);
|
KafkaStreams streams = new KafkaStreams(topology, streamsConfiguration);
|
||||||
streams.start();
|
streams.start();
|
||||||
|
|
||||||
//then
|
// then
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
streams.close();
|
streams.close();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
## Data Libraries
|
|
||||||
|
|
||||||
This module contains articles about libraries for data processing in Java.
|
|
||||||
|
|
||||||
### Relevant articles
|
|
||||||
|
|
||||||
|
|
||||||
##### Building the project
|
|
||||||
You can build the project from the command line using: *mvn clean install*, or in an IDE.
|
|
@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>libraries-data-3</artifactId>
|
|
||||||
<name>libraries-data-3</name>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
Loading…
x
Reference in New Issue
Block a user