query: 1.0.3 - application.server is derived from the local address
[demos/kafka/wordcount] / src / main / java / de / juplo / kafka / wordcount / query / QueryStreamProcessor.java
index 696e088..7e7af21 100644 (file)
@@ -14,7 +14,6 @@ import org.apache.kafka.streams.state.QueryableStoreTypes;
 import org.apache.kafka.streams.state.ReadOnlyKeyValueStore;
 import org.springframework.boot.SpringApplication;
 import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
@@ -27,7 +26,6 @@ import static org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler.St
 
 
 @Slf4j
-@Component
 public class QueryStreamProcessor
 {
        public final KafkaStreams streams;
@@ -38,14 +36,18 @@ public class QueryStreamProcessor
 
 
        public QueryStreamProcessor(
-                       QueryApplicationProperties properties,
+                       String applicationId,
+                       HostInfo applicationServer,
+                       String bootstrapServer,
+                       String usersInputTopic,
+                       String rankingInputTopic,
                        ObjectMapper mapper,
                        ConfigurableApplicationContext context)
        {
                StreamsBuilder builder = new StreamsBuilder();
 
-               KTable<String, String> users = builder.table(properties.getUsersInputTopic());
-               KStream<String, String> rankings = builder.stream(properties.getRankingInputTopic());
+               KTable<String, String> users = builder.table(usersInputTopic);
+               KStream<String, String> rankings = builder.stream(rankingInputTopic);
 
                rankings
                                .join(users, (rankingJson, userJson) ->
@@ -69,9 +71,9 @@ public class QueryStreamProcessor
                                .toTable(Materialized.as(storeName));
 
                Properties props = new Properties();
-               props.put(StreamsConfig.APPLICATION_ID_CONFIG, properties.getApplicationId());
-               props.put(StreamsConfig.APPLICATION_SERVER_CONFIG, properties.getApplicationServer());
-               props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, properties.getBootstrapServer());
+               props.put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId);
+               props.put(StreamsConfig.APPLICATION_SERVER_CONFIG, applicationServer.host() + ":" + applicationServer.port());
+               props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer);
                props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
                props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
                props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
@@ -88,7 +90,7 @@ public class QueryStreamProcessor
                        return SHUTDOWN_CLIENT;
                });
 
-               hostInfo = HostInfo.buildFromEndpoint(properties.getApplicationServer());
+               hostInfo = applicationServer;
                storeParameters = StoreQueryParameters.fromNameAndType(storeName, QueryableStoreTypes.keyValueStore());;
                this.mapper = mapper;
        }