From 6f7ec328ec507abb0e0c27167cf5f29a6776a376 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 15 Sep 2023 10:48:28 +0200 Subject: [PATCH] refactor: Extracted interface `WorkAssignor` into separate file --- .../implementation/kafka/ConsumerTaskExecutor.java | 6 ------ .../implementation/kafka/KafkaServicesConfiguration.java | 9 ++++----- .../chat/backend/implementation/kafka/WorkAssignor.java | 9 +++++++++ .../juplo/kafka/chat/backend/KafkaConfigurationIT.java | 2 +- .../implementation/kafka/KafkaChatHomeServiceTest.java | 3 +-- 5 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/WorkAssignor.java diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ConsumerTaskExecutor.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ConsumerTaskExecutor.java index 881dd293..9425bdf4 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ConsumerTaskExecutor.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/ConsumerTaskExecutor.java @@ -44,10 +44,4 @@ public class ConsumerTaskExecutor consumerTaskJob.join(); log.info("Joined the consumer-task for {}", consumerTask); } - - - public interface WorkAssignor - { - void assignWork(Consumer consumer); - } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java index 5bde07cd..b5bac470 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaServicesConfiguration.java @@ -51,7 +51,7 @@ public class KafkaServicesConfiguration ThreadPoolTaskExecutor taskExecutor, InfoChannel infoChannel, Consumer infoChannelConsumer, - ConsumerTaskExecutor.WorkAssignor infoChannelWorkAssignor) + WorkAssignor infoChannelWorkAssignor) { return new ConsumerTaskExecutor( taskExecutor, @@ -61,8 +61,7 @@ public class KafkaServicesConfiguration } @Bean - ConsumerTaskExecutor.WorkAssignor infoChannelWorkAssignor( - ChatBackendProperties properties) + WorkAssignor infoChannelWorkAssignor(ChatBackendProperties properties) { return consumer -> { @@ -82,7 +81,7 @@ public class KafkaServicesConfiguration ThreadPoolTaskExecutor taskExecutor, DataChannel dataChannel, Consumer dataChannelConsumer, - ConsumerTaskExecutor.WorkAssignor dataChannelWorkAssignor) + WorkAssignor dataChannelWorkAssignor) { return new ConsumerTaskExecutor( taskExecutor, @@ -92,7 +91,7 @@ public class KafkaServicesConfiguration } @Bean - ConsumerTaskExecutor.WorkAssignor dataChannelWorkAssignor( + WorkAssignor dataChannelWorkAssignor( ChatBackendProperties properties, DataChannel dataChannel) { diff --git a/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/WorkAssignor.java b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/WorkAssignor.java new file mode 100644 index 00000000..2335e53e --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/implementation/kafka/WorkAssignor.java @@ -0,0 +1,9 @@ +package de.juplo.kafka.chat.backend.implementation.kafka; + +import org.apache.kafka.clients.consumer.Consumer; + + +public interface WorkAssignor +{ + void assignWork(Consumer consumer); +} diff --git a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java index 8fbc557c..a3d60758 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java @@ -90,7 +90,7 @@ class KafkaConfigurationIT extends AbstractConfigurationWithShardingIT static class KafkaConfigurationITConfiguration { @Bean - ConsumerTaskExecutor.WorkAssignor dataChannelWorkAssignor( + WorkAssignor dataChannelWorkAssignor( DataChannel dataChannel) { return consumer -> diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java index 23c1751a..434d997d 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java @@ -59,8 +59,7 @@ public class KafkaChatHomeServiceTest extends ChatHomeServiceWithShardsTest static class KafkaChatHomeTestConfiguration { @Bean - ConsumerTaskExecutor.WorkAssignor dataChannelWorkAssignor( - DataChannel dataChannel) + WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel) { return consumer -> { -- 2.20.1