From d69073b2486862ab68a289eb33a697442c1cd75c Mon Sep 17 00:00:00 2001 From: seheonnn Date: Mon, 13 May 2024 11:42:46 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8Frefactor:=20Kafka=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=9A=A9=20Consumer=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20=EC=A0=84=EC=86=A1=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weatherservice/kafka/Consumer.java | 31 ++++++++----------- .../weatherservice/kafka/Producer.java | 2 +- .../service/WeatherService.java | 5 ++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/weather-service/src/main/java/com/waither/weatherservice/kafka/Consumer.java b/weather-service/src/main/java/com/waither/weatherservice/kafka/Consumer.java index b846262f..4afd624a 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/kafka/Consumer.java +++ b/weather-service/src/main/java/com/waither/weatherservice/kafka/Consumer.java @@ -1,20 +1,15 @@ package com.waither.weatherservice.kafka; -import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Component; - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@Component -@RequiredArgsConstructor -public class Consumer { - - @KafkaListener(topics = "${spring.kafka.template.topic}", groupId = "${spring.kafka.consumer.group-id}") - public void dailyWeatherConsume(String message) { - - log.info("Consumer Test ========================== "); - log.info("[*] Consumer Message {} ", message); - } -} +// 테스트용 Consumer +// @Slf4j +// @Component +// @RequiredArgsConstructor +// public class Consumer { +// +// @KafkaListener(topics = "${spring.kafka.template.topic}", groupId = "${spring.kafka.consumer.group-id}") +// public void dailyWeatherConsume(String message) { +// +// log.info("Consumer Test ========================== "); +// log.info("[*] Consumer Message {} ", message); +// } +// } 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 057fa514..868c2298 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 @@ -17,7 +17,7 @@ public class Producer { @Value("${spring.kafka.template.topic}") private String topic; - public void dailyWeatherProduceMessage(String message) { + public void produceMessage(String message) { log.info("[*] Producer Message : {}", message); kafkaTemplate.send(topic, message); } 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 fa7603b6..8d120d2c 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 @@ -61,7 +61,6 @@ public void createExpectedWeather( .expectedSky(expectedSkyList) .build(); - // TODO 조회 테스트 후 삭제 예정 ExpectedWeather save = expectedWeatherRepository.save(expectedWeather); log.info("[*] 예상 기후 : {}", save); } @@ -97,7 +96,8 @@ public void createDailyWeather(int nx, // DailyWeatherKafkaMessage kafkaMessage = DailyWeatherKafkaMessage.from(dailyWeather); - producer.dailyWeatherProduceMessage(wsd); + // 바람 세기 Kafka 전송 + producer.produceMessage(wsd); // DailyWeather save = dailyWeatherRepository.save(dailyWeather); log.info("[*] 하루 온도 : {}", dailyWeather); @@ -117,7 +117,6 @@ public void createDisasterMsg(String location) throws URISyntaxException, IOExce .message(msg) .build(); - // TODO 조회 테스트 후 삭제 예정 DisasterMessage save = disasterMessageRepository.save(disasterMessage); log.info("[*] 재난 문자 : {}", save); }