package de.juplo.kafka;
-import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
public class ApplicationConfiguration
{
@Bean
- public WordcountRecordHandler wordcountRecordHandler(
- PartitionStatisticsRepository repository,
- Consumer<String, String> consumer,
- ApplicationProperties properties)
+ public ApplicationRecordHandler recordHandler(AdderResults adderResults)
{
- return new WordcountRecordHandler(
- repository,
- properties.getClientId(),
- properties.getTopic(),
- Clock.systemDefaultZone(),
- properties.getCommitInterval(),
- consumer);
+ return new ApplicationRecordHandler(adderResults);
+ }
+
+ @Bean
+ public AdderResults adderResults()
+ {
+ return new AdderResults();
}
@Bean
- public WordcountRebalanceListener wordcountRebalanceListener(
- WordcountRecordHandler wordcountRecordHandler)
+ public ApplicationRebalanceListener rebalanceListener(
+ ApplicationRecordHandler recordHandler,
+ AdderResults adderResults,
+ StateRepository stateRepository,
+ ApplicationProperties properties)
{
- return new WordcountRebalanceListener(wordcountRecordHandler);
+ return new ApplicationRebalanceListener(
+ recordHandler,
+ adderResults,
+ stateRepository,
+ properties.getClientId(),
+ Clock.systemDefaultZone(),
+ properties.getCommitInterval());
}
@Bean
public EndlessConsumer<String, String> endlessConsumer(
KafkaConsumer<String, String> kafkaConsumer,
ExecutorService executor,
- WordcountRebalanceListener wordcountRebalanceListener,
- WordcountRecordHandler wordcountRecordHandler,
+ ApplicationRebalanceListener rebalanceListener,
+ ApplicationRecordHandler recordHandler,
ApplicationProperties properties)
{
return
properties.getClientId(),
properties.getTopic(),
kafkaConsumer,
- wordcountRebalanceListener,
- wordcountRecordHandler);
+ rebalanceListener,
+ recordHandler);
}
@Bean
props.put("partition.assignment.strategy", "org.apache.kafka.clients.consumer.CooperativeStickyAssignor");
props.put("group.id", properties.getGroupId());
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("value.deserializer", StringDeserializer.class.getName());