projects
/
demos
/
kafka
/
training
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Verbesserungen aus 'deserialization' nach 'stored-offsets' gemerged
[demos/kafka/training]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
ApplicationConfiguration.java
diff --git
a/src/main/java/de/juplo/kafka/ApplicationConfiguration.java
b/src/main/java/de/juplo/kafka/ApplicationConfiguration.java
index
0d17823
..
3925fcb
100644
(file)
--- a/
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
+++ b/
src/main/java/de/juplo/kafka/ApplicationConfiguration.java
@@
-2,6
+2,7
@@
package de.juplo.kafka;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.apache.kafka.common.serialization.LongDeserializer;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@
-18,39
+19,34
@@
import java.util.concurrent.Executors;
public class ApplicationConfiguration
{
@Bean
public class ApplicationConfiguration
{
@Bean
- public WordcountRecordHandler wordcountRecordHandler(
- PartitionStatisticsRepository repository,
- Consumer<String, String> consumer,
- ApplicationProperties properties)
+ public KeyCountingRecordHandler messageCountingRecordHandler()
{
{
- return new WordcountRecordHandler(
- repository,
- properties.getTopic(),
- Clock.systemDefaultZone(),
- properties.getCommitInterval(),
- consumer);
+ return new KeyCountingRecordHandler();
}
@Bean
}
@Bean
- public
Wordcount
RebalanceListener wordcountRebalanceListener(
-
WordcountRecordHandler wordcount
RecordHandler,
+ public
KeyCounting
RebalanceListener wordcountRebalanceListener(
+
KeyCountingRecordHandler keyCounting
RecordHandler,
PartitionStatisticsRepository repository,
PartitionStatisticsRepository repository,
- Consumer<String,
Stri
ng> consumer,
+ Consumer<String,
Lo
ng> consumer,
ApplicationProperties properties)
{
ApplicationProperties properties)
{
- return new
Wordcount
RebalanceListener(
-
wordcount
RecordHandler,
+ return new
KeyCounting
RebalanceListener(
+
keyCounting
RecordHandler,
repository,
properties.getClientId(),
repository,
properties.getClientId(),
+ properties.getTopic(),
+ Clock.systemDefaultZone(),
+ properties.getCommitInterval(),
consumer);
}
@Bean
consumer);
}
@Bean
- public EndlessConsumer<String,
Stri
ng> endlessConsumer(
- KafkaConsumer<String,
Stri
ng> kafkaConsumer,
+ public EndlessConsumer<String,
Lo
ng> endlessConsumer(
+ KafkaConsumer<String,
Lo
ng> kafkaConsumer,
ExecutorService executor,
ExecutorService executor,
-
WordcountRebalanceListener wordcount
RebalanceListener,
-
WordcountRecordHandler wordcount
RecordHandler,
+
KeyCountingRebalanceListener keyCounting
RebalanceListener,
+
KeyCountingRecordHandler keyCounting
RecordHandler,
ApplicationProperties properties)
{
return
ApplicationProperties properties)
{
return
@@
-59,8
+55,8
@@
public class ApplicationConfiguration
properties.getClientId(),
properties.getTopic(),
kafkaConsumer,
properties.getClientId(),
properties.getTopic(),
kafkaConsumer,
-
wordcount
RebalanceListener,
-
wordcount
RecordHandler);
+
keyCounting
RebalanceListener,
+
keyCounting
RecordHandler);
}
@Bean
}
@Bean
@@
-70,7
+66,7
@@
public class ApplicationConfiguration
}
@Bean(destroyMethod = "close")
}
@Bean(destroyMethod = "close")
- public KafkaConsumer<String,
Stri
ng> kafkaConsumer(ApplicationProperties properties)
+ public KafkaConsumer<String,
Lo
ng> kafkaConsumer(ApplicationProperties properties)
{
Properties props = new Properties();
{
Properties props = new Properties();
@@
-80,9
+76,10
@@
public class ApplicationConfiguration
props.put("client.id", properties.getClientId());
props.put("enable.auto.commit", false);
props.put("auto.offset.reset", properties.getAutoOffsetReset());
props.put("client.id", properties.getClientId());
props.put("enable.auto.commit", false);
props.put("auto.offset.reset", properties.getAutoOffsetReset());
+ props.put("auto.commit.interval.ms", (int)properties.getCommitInterval().toMillis());
props.put("metadata.max.age.ms", "1000");
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("metadata.max.age.ms", "1000");
props.put("key.deserializer", StringDeserializer.class.getName());
- props.put("value.deserializer",
Stri
ngDeserializer.class.getName());
+ props.put("value.deserializer",
Lo
ngDeserializer.class.getName());
return new KafkaConsumer<>(props);
}
return new KafkaConsumer<>(props);
}