splitter: 1.0.0-spring-integration - Inital implementation (incomplete)
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / splitter / SplitterApplication.java
index d46a7cd..412f429 100644 (file)
@@ -4,20 +4,43 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
-
-import java.time.Clock;
+import org.springframework.expression.common.LiteralExpression;
+import org.springframework.integration.annotation.InboundChannelAdapter;
+import org.springframework.integration.annotation.ServiceActivator;
+import org.springframework.integration.config.EnableIntegration;
+import org.springframework.integration.kafka.inbound.KafkaMessageSource;
+import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.core.KafkaTemplate;
+import org.springframework.kafka.listener.ConsumerProperties;
+import org.springframework.messaging.MessageHandler;
 
 
 @SpringBootApplication
 @EnableConfigurationProperties(SplitterApplicationProperties.class)
+@EnableIntegration
 public class SplitterApplication
 {
+       @InboundChannelAdapter(channel = "recordings")
        @Bean
-       Clock clock()
+       KafkaMessageSource<String, String> source(
+                       ConsumerFactory<String, String> cf,
+                       SplitterApplicationProperties properties)
        {
-               return Clock.systemDefaultZone();
+               return new KafkaMessageSource<>(cf, new ConsumerProperties(properties.getInputTopic()));
        }
 
+       @Bean
+       @ServiceActivator(inputChannel = "words")
+       MessageHandler handler(
+                       KafkaTemplate<String, String> kafkaTemplate,
+                       SplitterApplicationProperties properties)
+       {
+               KafkaProducerMessageHandler<String, String> handler =
+                               new KafkaProducerMessageHandler<>(kafkaTemplate);
+               handler.setTopicExpression(new LiteralExpression(properties.getOutputTopic()));
+               return handler;
+       }
 
        public static void main(String[] args)
        {