Die App führt die Berechnung aus
[demos/kafka/training] / src / main / java / de / juplo / kafka / ApplicationConfiguration.java
1 package de.juplo.kafka;
2
3 import org.apache.kafka.clients.consumer.Consumer;
4 import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
5 import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration;
8
9 import org.springframework.kafka.core.ConsumerFactory;
10
11
12 @Configuration
13 @EnableConfigurationProperties({ KafkaProperties.class, ApplicationProperties.class })
14 public class ApplicationConfiguration
15 {
16   @Bean
17   public AdderBusinessLogic adder()
18   {
19     return new AdderBusinessLogic();
20   }
21
22   @Bean
23   public MessageHandler messageHandler(
24     KafkaProperties properties,
25     AdderBusinessLogic adder)
26   {
27     return new MessageHandler(
28       properties.getClientId(),
29       adder);
30   }
31
32   @Bean
33   public SimpleConsumer simpleConsumer(
34       Consumer<String, Message> kafkaConsumer,
35       MessageHandler messageHandler,
36       KafkaProperties kafkaProperties,
37       ApplicationProperties applicationProperties)
38   {
39     return
40         new SimpleConsumer(
41             kafkaProperties.getClientId(),
42             applicationProperties.getTopic(),
43             kafkaConsumer,
44             messageHandler);
45   }
46
47   @Bean
48   public Consumer<?, ?> kafkaConsumer(ConsumerFactory<?, ?> factory)
49   {
50     return factory.createConsumer();
51   }
52 }