recorder: 1.1.2 - The `JsonSerializer` is used for serialization
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / recorder / RecorderApplication.java
1 package de.juplo.kafka.wordcount.recorder;
2
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;
12
13 import java.util.Properties;
14
15
16 @SpringBootApplication
17 @EnableConfigurationProperties(RecorderApplicationProperties.class)
18 public class RecorderApplication
19 {
20         @Bean(destroyMethod = "close")
21         KafkaProducer<String, Recording> producer(RecorderApplicationProperties properties)
22         {
23                 Assert.hasText(properties.getBootstrapServer(), "juplo.wordcount.recorder.bootstrap-server must be set");
24
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);
29                 props.put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false);
30
31                 return new KafkaProducer<>(props);
32         }
33
34         public static void main(String[] args)
35         {
36                 SpringApplication.run(RecorderApplication.class, args);
37         }
38 }