1 package de.juplo.kafka.wordcount.recorder;
3 import org.apache.kafka.clients.producer.KafkaProducer;
4 import org.apache.kafka.clients.producer.ProducerConfig;
5 import org.springframework.boot.SpringApplication;
6 import org.springframework.boot.autoconfigure.SpringBootApplication;
7 import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.kafka.support.serializer.JsonSerializer;
10 import org.springframework.util.Assert;
12 import java.util.Properties;
15 @SpringBootApplication
16 @EnableConfigurationProperties(RecorderApplicationProperties.class)
17 public class RecorderApplication
19 @Bean(destroyMethod = "close")
20 KafkaProducer<String, Recording> producer(RecorderApplicationProperties properties)
22 Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set");
24 Properties props = new Properties();
25 props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.getBootstrapServer());
26 props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
27 props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
28 props.put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false);
30 return new KafkaProducer<>(props);
33 public static void main(String[] args)
35 SpringApplication.run(RecorderApplication.class, args);