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.apache.kafka.common.serialization.StringSerializer;
6 import org.springframework.boot.SpringApplication;
7 import org.springframework.boot.autoconfigure.SpringBootApplication;
8 import org.springframework.boot.context.properties.EnableConfigurationProperties;
9 import org.springframework.context.annotation.Bean;
10 import org.springframework.kafka.support.serializer.JsonSerializer;
11 import org.springframework.util.Assert;
13 import java.util.Properties;
16 @SpringBootApplication
17 @EnableConfigurationProperties(RecorderApplicationProperties.class)
18 public class RecorderApplication
20 @Bean(destroyMethod = "close")
21 KafkaProducer<String, Recording> producer(RecorderApplicationProperties properties)
23 Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set");
25 Properties props = new Properties();
26 props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.getBootstrapServer());
27 props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
28 props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
30 return new KafkaProducer<>(props);
33 public static void main(String[] args)
35 SpringApplication.run(RecorderApplication.class, args);