import org.springframework.context.annotation.Configuration;
import java.util.Properties;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ApplicationConfiguration
{
@Bean
- public EndlessConsumer endlessConsumer(
- KafkaConsumer<String, String> kafkaConsumer,
+ public RecordHandler noopRecordHandler()
+ {
+ return record -> {};
+ }
+
+ @Bean
+ public EndlessConsumer<String, Long> endlessConsumer(
+ KafkaConsumer<String, Long> kafkaConsumer,
+ ExecutorService executor,
+ RecordHandler noopRecordHandler,
ApplicationProperties properties)
{
return
- new EndlessConsumer(
- Executors.newFixedThreadPool(1),
+ new EndlessConsumer<>(
+ executor,
properties.getClientId(),
properties.getTopic(),
- kafkaConsumer);
+ kafkaConsumer,
+ noopRecordHandler);
+ }
+
+ @Bean
+ public ExecutorService executor()
+ {
+ return Executors.newSingleThreadExecutor();
}
@Bean(destroyMethod = "close")
- public KafkaConsumer<String, String> kafkaConsumer(ApplicationProperties properties)
+ public KafkaConsumer<String, Long> kafkaConsumer(ApplicationProperties properties)
{
Properties props = new Properties();
props.put("bootstrap.servers", properties.getBootstrapServer());
+ 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("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", LongDeserializer.class.getName());