splitter: 1.0.0-spring-integration - refactored configuration
authorKai Moritz <kai@juplo.de>
Thu, 30 Jun 2022 19:34:21 +0000 (21:34 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 30 Jun 2022 19:34:21 +0000 (21:34 +0200)
src/main/java/de/juplo/kafka/wordcount/splitter/SplitterApplication.java

index 0a70551..d9ba135 100644 (file)
@@ -29,10 +29,17 @@ import org.springframework.messaging.support.ChannelInterceptor;
 public class SplitterApplication
 {
        @Bean
-       MessageChannel words()
+       MessageChannel words(ChannelInterceptor keyInterceptor)
        {
                DirectChannel words = new DirectChannel();
-               words.addInterceptor(new ChannelInterceptor()
+               words.addInterceptor(keyInterceptor);
+               return words;
+       }
+
+       @Bean
+       ChannelInterceptor keyInterceptor ()
+       {
+               return new ChannelInterceptor()
                {
                        @Override
                        public Message<?> preSend(Message<?> message, MessageChannel channel)
@@ -45,8 +52,7 @@ public class SplitterApplication
                                                                .setHeader(KafkaHeaders.MESSAGE_KEY, key)
                                                                .build();
                        }
-               });
-               return words;
+               };
        }
 
        @InboundChannelAdapter(channel = "recordings")