package de.juplo.kafka;
import org.apache.kafka.clients.consumer.ConsumerRecord;
-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.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.core.ConsumerFactory;
-import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
@Bean
public EndlessConsumer<String, Long> endlessConsumer(
- KafkaConsumer<String, Long> kafkaConsumer,
+ org.apache.kafka.clients.consumer.Consumer<String, Long> kafkaConsumer,
ExecutorService executor,
Consumer<ConsumerRecord<String, Long>> handler,
KafkaProperties kafkaProperties,
}
@Bean(destroyMethod = "close")
- public KafkaConsumer<String, Long> kafkaConsumer(KafkaProperties properties)
+ public org.apache.kafka.clients.consumer.Consumer<String, Long> kafkaConsumer(ConsumerFactory<String, Long> factory)
{
- Properties props = new Properties();
-
- props.put("bootstrap.servers", properties.getConsumer().getBootstrapServers());
- props.put("group.id", properties.getConsumer().getGroupId());
- props.put("client.id", properties.getConsumer().getClientId());
- props.put("auto.offset.reset", properties.getConsumer().getAutoOffsetReset());
- props.put("metadata.max.age.ms", "1000");
- props.put("key.deserializer", StringDeserializer.class.getName());
- props.put("value.deserializer", LongDeserializer.class.getName());
-
- return new KafkaConsumer<>(props);
+ return factory.createConsumer();
}
}
import org.apache.kafka.common.utils.Bytes;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
import org.springframework.boot.test.context.TestConfiguration;
import static org.awaitility.Awaitility.*;
-@SpringJUnitConfig(initializers = ConfigDataApplicationContextInitializer.class)
+@SpringJUnitConfig(
+ initializers = ConfigDataApplicationContextInitializer.class,
+ classes = {
+ KafkaAutoConfiguration.class,
+ ApplicationTests.Configuration.class })
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestPropertySource(
properties = {
@Autowired
KafkaProducer<String, Bytes> kafkaProducer;
@Autowired
- KafkaConsumer<String, Long> kafkaConsumer;
+ org.apache.kafka.clients.consumer.Consumer<String, Long> kafkaConsumer;
@Autowired
KafkaConsumer<Bytes, Bytes> offsetConsumer;
@Autowired