bc617a85731baec478601a51c44e5b270368cff4
[demos/kafka/training] / src / main / java / de / juplo / kafka / Application.java
1 package de.juplo.kafka;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.boot.SpringApplication;
5 import org.springframework.boot.autoconfigure.SpringBootApplication;
6 import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.util.Assert;
9
10 import java.util.concurrent.Executors;
11
12
13 @SpringBootApplication
14 @EnableConfigurationProperties(ApplicationProperties.class)
15 public class Application
16 {
17   @Autowired
18   ApplicationProperties properties;
19
20
21   @Bean
22   public EndlessProducer producer()
23   {
24     Assert.hasText(properties.getBootstrapServer(), "producer.bootstrap-server must be set");
25     Assert.hasText(properties.getClientId(), "producer.client-id must be set");
26     Assert.hasText(properties.getTopic(), "producer.topic must be set");
27
28     EndlessProducer producer =
29         new EndlessProducer(
30             Executors.newFixedThreadPool(1),
31             properties.getBootstrapServer(),
32             properties.getClientId(),
33             properties.getTopic(),
34             properties.getAcks(),
35             properties.getThrottleMs());
36
37     producer.start();
38
39     return producer;
40   }
41
42   public static void main(String[] args)
43   {
44     SpringApplication.run(Application.class, args);
45   }
46 }