From 833a0dd9b91ced553c2592bac6ebc3b33f3e7fc9 Mon Sep 17 00:00:00 2001 From: seheonnn Date: Fri, 5 Jul 2024 14:59:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20main=20api=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../waither/weatherservice/kafka/Producer.java | 2 +- .../response/WeatherErrorCode.java | 12 ++++++++---- .../weatherservice/service/WeatherService.java | 16 +++++++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/weather-service/src/main/java/com/waither/weatherservice/kafka/Producer.java b/weather-service/src/main/java/com/waither/weatherservice/kafka/Producer.java index 79469436..df058477 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/kafka/Producer.java +++ b/weather-service/src/main/java/com/waither/weatherservice/kafka/Producer.java @@ -22,7 +22,7 @@ public void produceMessage(String topic, Object message) { kafkaTemplate.send(topic, message); - CompletableFuture> future = kafkaTemplate.send(topic, message); + CompletableFuture> future = kafkaTemplate.send(topic, "weather-key", message); future.whenComplete(((result, throwable) -> { if (throwable == null) { diff --git a/weather-service/src/main/java/com/waither/weatherservice/response/WeatherErrorCode.java b/weather-service/src/main/java/com/waither/weatherservice/response/WeatherErrorCode.java index a85bc889..173c95ca 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/response/WeatherErrorCode.java +++ b/weather-service/src/main/java/com/waither/weatherservice/response/WeatherErrorCode.java @@ -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; diff --git a/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java b/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java index f1449d5e..95f4eeba 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java +++ b/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java @@ -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(), @@ -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; } @@ -222,8 +230,6 @@ public LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) } public List getRegionList() { - List all = regionRepository.findAll(); - // log.info("Region List : {}", all); return regionRepository.findAll(); } From c25a22bd158f0782d233998c034744aea4b87826 Mon Sep 17 00:00:00 2001 From: seheonnn Date: Fri, 5 Jul 2024 15:59:58 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Kafka=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/waither/weatherservice/kafka/KafkaConfig.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/weather-service/src/main/java/com/waither/weatherservice/kafka/KafkaConfig.java b/weather-service/src/main/java/com/waither/weatherservice/kafka/KafkaConfig.java index 06a51297..0adf0709 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/kafka/KafkaConfig.java +++ b/weather-service/src/main/java/com/waither/weatherservice/kafka/KafkaConfig.java @@ -45,6 +45,11 @@ private ProducerFactory producerFactory(Class 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); }