From fddc8bd8ef94164f7e448e311c03df9eb0e5ee4d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 10 May 2019 10:45:46 +0200 Subject: [PATCH] Create Kafka sample topic --- .../main/java/sample/kafka/SampleKafkaApplication.java | 9 ++++++++- .../java/sample/kafka/SampleKafkaApplicationTests.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java index c506b8b721..6cce2bb4ea 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/main/java/sample/kafka/SampleKafkaApplication.java @@ -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")); diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java index fd0832f8e4..a7d1b66fc1 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java @@ -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