From 8aaf63efd2d666aa43825ef99f81de394788fc20 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 30 Jun 2022 21:34:21 +0200 Subject: [PATCH] splitter: 1.0.0-spring-integration - refactored configuration --- .../wordcount/splitter/SplitterApplication.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/juplo/kafka/wordcount/splitter/SplitterApplication.java b/src/main/java/de/juplo/kafka/wordcount/splitter/SplitterApplication.java index 0a70551..d9ba135 100644 --- a/src/main/java/de/juplo/kafka/wordcount/splitter/SplitterApplication.java +++ b/src/main/java/de/juplo/kafka/wordcount/splitter/SplitterApplication.java @@ -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") -- 2.20.1