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;
@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();