Commit fddc8bd8 authored by Stephane Nicoll's avatar Stephane Nicoll

Create Kafka sample topic

parent 555dd3bc
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package sample.kafka; package sample.kafka;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -28,6 +30,11 @@ public class SampleKafkaApplication { ...@@ -28,6 +30,11 @@ public class SampleKafkaApplication {
SpringApplication.run(SampleKafkaApplication.class, args); SpringApplication.run(SampleKafkaApplication.class, args);
} }
@Bean
public NewTopic kafkaTestTopic() {
return new NewTopic("testTopic", 10, (short) 2);
}
@Bean @Bean
public ApplicationRunner runner(Producer producer) { public ApplicationRunner runner(Producer producer) {
return (args) -> producer.send(new SampleMessage(1, "A simple test message")); return (args) -> producer.send(new SampleMessage(1, "A simple test message"));
......
...@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@SpringBootTest( @SpringBootTest(
properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}") properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}")
@EmbeddedKafka @EmbeddedKafka(topics = "testTopic")
class SampleKafkaApplicationTests { class SampleKafkaApplicationTests {
@RegisterExtension @RegisterExtension
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment