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;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
- public Consumer<ConsumerRecord<String, Long>> consumer()
+ public WordcountRecordHandler wordcountRecordHandler(
+ PartitionStatisticsRepository repository,
+ Consumer<String, String> consumer,
+ ApplicationProperties properties)
- return (record) ->
- {
- // Handle record
- };
+ return new WordcountRecordHandler(
+ repository,
+ properties.getClientId(),
+ properties.getTopic(),
+ Clock.systemDefaultZone(),
+ properties.getCommitInterval(),
+ consumer);
- public EndlessConsumer<String, Long> endlessConsumer(
- KafkaConsumer<String, Long> kafkaConsumer,
+ public WordcountRebalanceListener wordcountRebalanceListener(
+ WordcountRecordHandler wordcountRecordHandler)
+ {
+ return new WordcountRebalanceListener(wordcountRecordHandler);
+ }
+
+ @Bean
+ public EndlessConsumer<String, String> endlessConsumer(
+ KafkaConsumer<String, String> kafkaConsumer,
- Consumer<ConsumerRecord<String, Long>> handler,
- PartitionStatisticsRepository repository,
+ WordcountRebalanceListener wordcountRebalanceListener,
+ WordcountRecordHandler wordcountRecordHandler,
{
Properties props = new Properties();
props.put("bootstrap.servers", properties.getBootstrapServer());
{
Properties props = new Properties();
props.put("bootstrap.servers", properties.getBootstrapServer());
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("metadata.max.age.ms", "1000");
props.put("key.deserializer", StringDeserializer.class.getName());
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("metadata.max.age.ms", "1000");
props.put("key.deserializer", StringDeserializer.class.getName());