Create Kafka sample topic

pull/16831/head
Stephane Nicoll 6 years ago
parent 555dd3bcaa
commit fddc8bd8ef

@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
package sample.kafka;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -28,6 +30,11 @@ public class SampleKafkaApplication {
SpringApplication.run(SampleKafkaApplication.class, args);
}
@Bean
public NewTopic kafkaTestTopic() {
return new NewTopic("testTopic", 10, (short) 2);
}
@Bean
public ApplicationRunner runner(Producer producer) {
return (args) -> producer.send(new SampleMessage(1, "A simple test message"));

@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@SpringBootTest(
properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}")
@EmbeddedKafka
@EmbeddedKafka(topics = "testTopic")
class SampleKafkaApplicationTests {
@RegisterExtension

Loading…
Cancel
Save