init
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.k12study.aiclient.client;
|
||||
|
||||
import com.k12study.api.ai.dto.AiHealthDto;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
public class HttpPythonAiClient implements PythonAiClient {
|
||||
private final RestClient restClient;
|
||||
|
||||
public HttpPythonAiClient(RestClient restClient) {
|
||||
this.restClient = restClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiHealthDto health() {
|
||||
try {
|
||||
AiHealthDto response = restClient.get()
|
||||
.uri("/health")
|
||||
.retrieve()
|
||||
.body(AiHealthDto.class);
|
||||
return response == null ? new AiHealthDto("python-ai", "UNKNOWN", "0.1.0") : response;
|
||||
} catch (Exception exception) {
|
||||
return new AiHealthDto("python-ai", "UNREACHABLE", "0.1.0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.k12study.aiclient.client;
|
||||
|
||||
import com.k12study.api.ai.dto.AiHealthDto;
|
||||
|
||||
public interface PythonAiClient {
|
||||
AiHealthDto health();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.k12study.aiclient.config;
|
||||
|
||||
import com.k12study.aiclient.client.HttpPythonAiClient;
|
||||
import com.k12study.aiclient.client.PythonAiClient;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AiClientProperties.class)
|
||||
public class AiClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public RestClient aiRestClient(AiClientProperties properties) {
|
||||
return RestClient.builder().baseUrl(properties.getBaseUrl()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PythonAiClient pythonAiClient(RestClient aiRestClient) {
|
||||
return new HttpPythonAiClient(aiRestClient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.k12study.aiclient.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "ai.client")
|
||||
public class AiClientProperties {
|
||||
private String baseUrl = "http://localhost:9000";
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user