Skip to content

Commit fddc8bd

Browse files
committed
Create Kafka sample topic
1 parent 555dd3b commit fddc8bd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package sample.kafka;
1818

19+
import org.apache.kafka.clients.admin.NewTopic;
20+
1921
import org.springframework.boot.ApplicationRunner;
2022
import org.springframework.boot.SpringApplication;
2123
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -28,6 +30,11 @@ public static void main(String[] args) {
2830
SpringApplication.run(SampleKafkaApplication.class, args);
2931
}
3032

33+
@Bean
34+
public NewTopic kafkaTestTopic() {
35+
return new NewTopic("testTopic", 10, (short) 2);
36+
}
37+
3138
@Bean
3239
public ApplicationRunner runner(Producer producer) {
3340
return (args) -> producer.send(new SampleMessage(1, "A simple test message"));

spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
@SpringBootTest(
3535
properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}")
36-
@EmbeddedKafka
36+
@EmbeddedKafka(topics = "testTopic")
3737
class SampleKafkaApplicationTests {
3838

3939
@RegisterExtension

0 commit comments

Comments
 (0)