I wanted to use embedded Kafka for a Spring boot application. I am able to use embedded Kafka for Junit testing, but while trying to use in main application, the embedded Kafka object is not being identified.
When trying to load Spring boot application the embedded kafka object is not being autowired. This is for NON testing flow.
@SpringBootApplication
@DirtiesContext
@EmbeddedKafka(topics = "TEST_TOPIC.P2.R2", partitions = 1, controlledShutdown = false, brokerProperties = {
"listeners=PLAINTEXT://localhost:9092", "port=9092" })
public class MockKafkaProducerApplication {
public static void main(String[] args) throws Exception {
System.out.println("Starting Spring boot Application");
SpringApplication.run(MockKafkaProducerApplication.class, args);
}
}
@ActiveProfiles("kafka_test")
@Configuration
public class KafkaConsumerTestBase {
private Logger LOGGER = LoggerFactory.getLogger(KafkaConsumerTestBase.class);
@Autowired
protected EmbeddedKafkaBroker embeddedKafka;
@Value("${spring.embedded.kafka.brokers}")
private String brokerAddress;
@Autowired
protected KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry;
@Autowired
protected KafkaTemplate<String, String> senderTemplate;
....... ........ }
Field embeddedKafka in com.dell.pde.kafka.KafkaConsumerTestBase required a bean of type 'org.springframework.kafka.test.EmbeddedKafkaBroker' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)