From 194a4fa4c90d322f4e95d4b3b6ffe75dc46945c2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 9 Jun 2024 09:29:12 +0200 Subject: [PATCH] query: 1.0.6 - Separated config in `Top10ApplicationConfiguration` -- ALIGN --- .../wordcount/query/QueryApplication.java | 44 ------------------- .../query/QueryApplicationConfiguration.java | 15 ++----- 2 files changed, 4 insertions(+), 55 deletions(-) diff --git a/src/main/java/de/juplo/kafka/wordcount/query/QueryApplication.java b/src/main/java/de/juplo/kafka/wordcount/query/QueryApplication.java index 813d3b2..eeee7eb 100644 --- a/src/main/java/de/juplo/kafka/wordcount/query/QueryApplication.java +++ b/src/main/java/de/juplo/kafka/wordcount/query/QueryApplication.java @@ -1,56 +1,12 @@ package de.juplo.kafka.wordcount.query; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.kafka.streams.state.HostInfo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.Bean; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; @SpringBootApplication -@EnableConfigurationProperties(QueryApplicationProperties.class) public class QueryApplication { - @Bean - public QueryStreamProcessor usersStreamProcessor( - ServerProperties serverProperties, - QueryApplicationProperties properties, - ObjectMapper mapper, - ConfigurableApplicationContext context) throws IOException - { - String host; - if (serverProperties.getAddress() == null) - { - HostInfo bootstrapServer = HostInfo.buildFromEndpoint(properties.getBootstrapServer()); - Socket socket = new Socket(); - socket.connect(new InetSocketAddress(bootstrapServer.host(), bootstrapServer.port())); - host = socket.getLocalAddress().getHostAddress(); - } - else - { - host = serverProperties.getAddress().getHostAddress(); - } - - Integer port = serverProperties.getPort() == null ? 8080 : serverProperties.getPort(); - - return new QueryStreamProcessor( - properties.getApplicationId(), - new HostInfo(host, port), - properties.getBootstrapServer(), - properties.getUsersInputTopic(), - properties.getRankingInputTopic(), - mapper, - context); - } - - public static void main(String[] args) { SpringApplication.run(QueryApplication.class, args); diff --git a/src/main/java/de/juplo/kafka/wordcount/query/QueryApplicationConfiguration.java b/src/main/java/de/juplo/kafka/wordcount/query/QueryApplicationConfiguration.java index 813d3b2..dfc4339 100644 --- a/src/main/java/de/juplo/kafka/wordcount/query/QueryApplicationConfiguration.java +++ b/src/main/java/de/juplo/kafka/wordcount/query/QueryApplicationConfiguration.java @@ -2,24 +2,23 @@ package de.juplo.kafka.wordcount.query; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.kafka.streams.state.HostInfo; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; -@SpringBootApplication +@Configuration @EnableConfigurationProperties(QueryApplicationProperties.class) -public class QueryApplication +public class QueryApplicationConfiguration { @Bean - public QueryStreamProcessor usersStreamProcessor( + public QueryStreamProcessor streamProcessor( ServerProperties serverProperties, QueryApplicationProperties properties, ObjectMapper mapper, @@ -49,10 +48,4 @@ public class QueryApplication mapper, context); } - - - public static void main(String[] args) - { - SpringApplication.run(QueryApplication.class, args); - } } -- 2.20.1