Spring-Version des Endless-Stream-Producer's
[demos/kafka/training] / src / main / java / de / juplo / kafka / Application.java
index bc617a8..0719459 100644 (file)
@@ -1,10 +1,11 @@
 package de.juplo.kafka;
 
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
+import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.util.Assert;
 
 import java.util.concurrent.Executors;
@@ -14,25 +15,19 @@ import java.util.concurrent.Executors;
 @EnableConfigurationProperties(ApplicationProperties.class)
 public class Application
 {
-  @Autowired
-  ApplicationProperties properties;
-
-
   @Bean
-  public EndlessProducer producer()
+  public EndlessProducer producer(
+      ApplicationProperties properties,
+      @Value("${spring.kafka.client-id:DEV}") String clientId,
+      KafkaTemplate<String, String> kafkaTemplate)
   {
-    Assert.hasText(properties.getBootstrapServer(), "producer.bootstrap-server must be set");
-    Assert.hasText(properties.getClientId(), "producer.client-id must be set");
-    Assert.hasText(properties.getTopic(), "producer.topic must be set");
 
     EndlessProducer producer =
         new EndlessProducer(
             Executors.newFixedThreadPool(1),
-            properties.getBootstrapServer(),
-            properties.getClientId(),
-            properties.getTopic(),
-            properties.getAcks(),
-            properties.getThrottleMs());
+            clientId,
+            properties.getThrottleMs(),
+            kafkaTemplate);
 
     producer.start();