</parent>
<groupId>de.juplo.kafka.wordcount</groupId>
<artifactId>counter</artifactId>
- <version>1.2.9</version>
+ <version>1.2.10</version>
<name>Wordcount-Counter</name>
<description>Word-counting stream-processor of the multi-user wordcount-example</description>
<properties>
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.streams.KeyValue;
import org.apache.kafka.streams.state.KeyValueBytesStoreSupplier;
import org.apache.kafka.streams.state.Stores;
import org.junit.jupiter.api.BeforeEach;
@RequiredArgsConstructor
static class Consumer
{
- private final List<Message> received = new LinkedList<>();
+ private final List<KeyValue<Word, WordCount>> received = new LinkedList<>();
@KafkaListener(groupId = "TEST", topics = TOPIC_OUT)
public synchronized void receive(ConsumerRecord<Word, WordCount> record)
{
log.debug("Received message: {}", record);
- received.add(Message.of(record.key(),record.value()));
+ received.add(KeyValue.pair(record.key(),record.value()));
}
- synchronized List<Message> getReceivedMessages()
+ synchronized List<KeyValue<Word, WordCount>> getReceivedMessages()
{
return received;
}
package de.juplo.kafka.wordcount.counter;
-import org.apache.kafka.streams.TestInputTopic;
-import org.apache.kafka.streams.TestOutputTopic;
-import org.apache.kafka.streams.Topology;
-import org.apache.kafka.streams.TopologyTestDriver;
+import org.apache.kafka.streams.*;
import org.apache.kafka.streams.state.Stores;
import org.junit.jupiter.api.Test;
import org.springframework.kafka.support.serializer.JsonDeserializer;
TestData.writeInputData((key, value) -> in.pipeInput(key, value));
- List<Message> receivedMessages = out
+ List<KeyValue<Word,WordCount>> receivedMessages = out
.readRecordsToList()
.stream()
- .map(record -> Message.of(record.key(), record.value()))
+ .map(record -> KeyValue.pair(record.key(), record.value()))
.toList();
TestData.assertExpectedResult(receivedMessages);
+++ /dev/null
-package de.juplo.kafka.wordcount.counter;
-
-import lombok.Value;
-
-
-@Value(staticConstructor = "of")
-public class Message
-{
- Word key;
- WordCount value;
-}
package de.juplo.kafka.wordcount.counter;
+import org.apache.kafka.streams.KeyValue;
+
import java.util.List;
import java.util.function.BiConsumer;
Word.of("klaus","s"));
}
- static void assertExpectedResult(List<Message> receivedMessages)
+ static void assertExpectedResult(List<KeyValue<Word, WordCount>> receivedMessages)
{
assertThat(receivedMessages).hasSize(11);
assertThat(receivedMessages).containsSubsequence(
expectedMessages[9]); // Boäh
}
- static Message[] expectedMessages =
+ static KeyValue<Word,WordCount>[] expectedMessages = new KeyValue[]
{
- Message.of(
+ KeyValue.pair(
Word.of("peter","Hallo"),
WordCount.of("peter","Hallo",1)),
- Message.of(
+ KeyValue.pair(
Word.of("klaus","Müsch"),
WordCount.of("klaus","Müsch",1)),
- Message.of(
+ KeyValue.pair(
Word.of("peter","Welt"),
WordCount.of("peter","Welt",1)),
- Message.of(
+ KeyValue.pair(
Word.of("klaus","Müsch"),
WordCount.of("klaus","Müsch",2)),
- Message.of(
+ KeyValue.pair(
Word.of("klaus","s"),
WordCount.of("klaus","s",1)),
- Message.of(
+ KeyValue.pair(
Word.of("peter","Boäh"),
WordCount.of("peter","Boäh",1)),
- Message.of(
+ KeyValue.pair(
Word.of("peter","Welt"),
WordCount.of("peter","Welt",2)),
- Message.of(
+ KeyValue.pair(
Word.of("peter","Boäh"),
WordCount.of("peter","Boäh",2)),
- Message.of(
+ KeyValue.pair(
Word.of("klaus","s"),
WordCount.of("klaus","s",2)),
- Message.of(
+ KeyValue.pair(
Word.of("peter","Boäh"),
WordCount.of("peter","Boäh",3)),
- Message.of(
+ KeyValue.pair(
Word.of("klaus","s"),
WordCount.of("klaus","s",3)),
};