Skip to content

Commit

Permalink
Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
seheonnn authored Jul 5, 2024
2 parents 00325a6 + 5847d95 commit d3cf915
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ private <T> ProducerFactory<String, T> producerFactory(Class<T> valueClass) {
config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
}

config.put(ProducerConfig.RETRIES_CONFIG, 3);
config.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, 60000);
config.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, 5);


return new DefaultKafkaProducerFactory<>(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void produceMessage(String topic, Object message) {

kafkaTemplate.send(topic, message);

CompletableFuture<SendResult<String, Object>> future = kafkaTemplate.send(topic, message);
CompletableFuture<SendResult<String, Object>> future = kafkaTemplate.send(topic, "weather-key", message);

future.whenComplete(((result, throwable) -> {
if (throwable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
@AllArgsConstructor
public enum WeatherErrorCode implements BaseErrorCode {

WEATHER_EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "WEAT4000", "날씨 에러입니다."),
WEATHER_OPENAPI_ERROR(HttpStatus.BAD_REQUEST, "WEAT4010", "OpenApi 관련 오류입니다."),
WEATHER_MAIN_ERROR(HttpStatus.BAD_REQUEST, "WEAT4020", "잘못된 위도, 경도입니다."), // 레디스에 캐싱 데이터가 없는 경우
WEATHER_URI_ERROR(HttpStatus.BAD_REQUEST, "WEAT4030", "URI 변환에 실패하였습니다.");
WEATHER_EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "WEAT400_0", "날씨 에러입니다."),
WEATHER_OPENAPI_ERROR(HttpStatus.BAD_REQUEST, "WEAT400_3", "OpenApi 관련 오류입니다."),
WEATHER_MAIN_ERROR(HttpStatus.BAD_REQUEST, "WEAT400_2", "잘못된 위도, 경도입니다."), // 레디스에 캐싱 데이터가 없는 경우
WEATHER_URI_ERROR(HttpStatus.BAD_REQUEST, "WEAT400_3", "URI 변환에 실패하였습니다."),
REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "WEAT400_4", "URI 변환에 실패하였습니다."),
DAILY_NOT_FOUND(HttpStatus.NOT_FOUND, "WEAT400_5", "URI 변환에 실패하였습니다."),
EXPECTED_NOT_FOUND(HttpStatus.NOT_FOUND, "WEAT400_6", "URI 변환에 실패하였습니다."),
;

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,24 @@ public MainWeatherResponse getMainWeather(double latitude, double longitude) {
if (region.isEmpty())
throw new WeatherExceptionHandler(WeatherErrorCode.WEATHER_MAIN_ERROR);

String expectedWeatherKey = region.get(0).getRegionName() + "_" + convertLocalDateTimeToString(now);
String regionName = region.get(0).getRegionName();

log.info("region : {}", regionName);

String expectedWeatherKey = regionName + "_" + convertLocalDateTimeToString(now);

String dailyWeatherKey = region.get(0).getRegionName() + "_" + convertLocalDateTimeToDailyWeatherTime(now);
String dailyWeatherKey = regionName + "_" + convertLocalDateTimeToDailyWeatherTime(now);

DailyWeather dailyWeather = dailyWeatherRepository.findById(dailyWeatherKey)
.orElseThrow(() -> new WeatherExceptionHandler(WeatherErrorCode.WEATHER_MAIN_ERROR));

log.info(regionName + "DailyWeather : {}", dailyWeather);

ExpectedWeather expectedWeather = expectedWeatherRepository.findById(expectedWeatherKey)
.orElseThrow(() -> new WeatherExceptionHandler(WeatherErrorCode.WEATHER_MAIN_ERROR));

log.info(regionName + "ExpectedWeather : {}", expectedWeather);

MainWeatherResponse weatherMainResponse = MainWeatherResponse.from(
dailyWeather.getPop(), dailyWeather.getTmp(), dailyWeather.getTempMin(),
dailyWeather.getTempMax(), dailyWeather.getHumidity(),
Expand All @@ -185,7 +193,7 @@ public MainWeatherResponse getMainWeather(double latitude, double longitude) {
expectedWeather.getExpectedRain(), expectedWeather.getExpectedPty(),
expectedWeather.getExpectedSky()
);
log.info("{}", weatherMainResponse);
log.info(regionName + "MainWeatherResponse : {}", weatherMainResponse);

return weatherMainResponse;
}
Expand Down Expand Up @@ -222,8 +230,6 @@ public LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time)
}

public List<Region> getRegionList() {
List<Region> all = regionRepository.findAll();
// log.info("Region List : {}", all);
return regionRepository.findAll();
}

Expand Down

0 comments on commit d3cf915

Please sign in to comment.