1 package de.juplo.kafka.wordcount.query;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import org.apache.kafka.streams.state.HostInfo;
5 import org.springframework.boot.autoconfigure.web.ServerProperties;
6 import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 import org.springframework.context.ConfigurableApplicationContext;
8 import org.springframework.context.annotation.Bean;
9 import org.springframework.context.annotation.Configuration;
11 import java.io.IOException;
12 import java.net.InetSocketAddress;
13 import java.net.Socket;
17 @EnableConfigurationProperties(QueryApplicationProperties.class)
18 public class QueryApplicationConfiguration
21 public QueryStreamProcessor streamProcessor(
22 ServerProperties serverProperties,
23 QueryApplicationProperties properties,
25 ConfigurableApplicationContext context) throws IOException
28 if (serverProperties.getAddress() == null)
30 HostInfo bootstrapServer = HostInfo.buildFromEndpoint(properties.getBootstrapServer());
31 Socket socket = new Socket();
32 socket.connect(new InetSocketAddress(bootstrapServer.host(), bootstrapServer.port()));
33 host = socket.getLocalAddress().getHostAddress();
37 host = serverProperties.getAddress().getHostAddress();
40 Integer port = serverProperties.getPort() == null ? 8080 : serverProperties.getPort();
42 return new QueryStreamProcessor(
43 properties.getApplicationId(),
44 new HostInfo(host, port),
45 properties.getBootstrapServer(),
46 properties.getUsersInputTopic(),
47 properties.getRankingInputTopic(),