Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ› fix: Kafka Consumer Type Mapping μ„€μ • μΆ”κ°€ #153

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ public ConcurrentKafkaListenerContainerFactory<String, KafkaDto.WeatherDto> weat

private ConsumerFactory<String, KafkaDto.WeatherDto> weatherConsumerFactory() {
Map<String, Object> props = dtoSettings();
props.put(JsonDeserializer.TYPE_MAPPINGS, "KafkaMessage:com.waither.notiservice.dto.kafka.KafkaDto.WeatherDto");
props.put(JsonDeserializer.TRUSTED_PACKAGES, "com.waither.*");
props.put(JsonDeserializer.TYPE_MAPPINGS, "com.waither.weatherservice.kafka.KafkaMessage:com.waither.notiservice.dto.kafka.KafkaDto$WeatherDto");
props.put(JsonDeserializer.TRUSTED_PACKAGES, "com.waither.*,com.waither.weatherservice.kafka");
props.put(JsonDeserializer.VALUE_DEFAULT_TYPE, "com.waither.notiservice.dto.kafka.KafkaDto$WeatherDto");
return new DefaultKafkaConsumerFactory<>(props, new StringDeserializer(), createJsonDeserializer(KafkaDto.WeatherDto.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -108,7 +109,7 @@ public void consumeUserInit(KafkaDto.InitialDataDto initialDataDto) {
* @Query : 0200, 0500, 0800, 1100, 1400, 1700, 2000, 2300 */
@Transactional
@KafkaListener(topics = "alarm-wind", containerFactory = "weatherKafkaListenerContainerFactory")
public void consumeWindAlarm(KafkaDto.WeatherDto weatherDto) {
public void consumeWindAlarm(@Payload KafkaDto.WeatherDto weatherDto) {

int currentHour = LocalDateTime.now().getHour();
// 22:00 ~ 07:00 λŠ” μ•Œλ¦Όμ„ μ „μ†‘ν•˜μ§€ μ•ŠμŒ
Expand Down Expand Up @@ -165,7 +166,7 @@ public void consumeWindAlarm(KafkaDto.WeatherDto weatherDto) {
*/
@Transactional
@KafkaListener(topics = "alarm-rain", containerFactory = "weatherKafkaListenerContainerFactory")
public void consumeRain(KafkaDto.WeatherDto weatherDto) {
public void consumeRain(@Payload KafkaDto.WeatherDto weatherDto) {

int currentHour = LocalDateTime.now().getHour();
// 22:00 ~ 07:00 λŠ” μ•Œλ¦Όμ„ μ „μ†‘ν•˜μ§€ μ•ŠμŒ
Expand Down Expand Up @@ -230,7 +231,7 @@ public void consumeRain(KafkaDto.WeatherDto weatherDto) {
* */
@Transactional
@KafkaListener(topics = "alarm-climate", containerFactory = "weatherKafkaListenerContainerFactory")
public void consumeClimateAlarm(KafkaDto.WeatherDto weatherDto) {
public void consumeClimateAlarm(@Payload KafkaDto.WeatherDto weatherDto) {
int currentHour = LocalDateTime.now().getHour();
// 22:00 ~ 07:00 λŠ” μ•Œλ¦Όμ„ μ „μ†‘ν•˜μ§€ μ•ŠμŒ
if (currentHour >= 22 || currentHour <= 7) {
Expand Down
Loading