diff --git a/src/main/java/com/catchroom/ChatApplication.java b/src/main/java/com/catchroom/ChatApplication.java index 7d568b6..1406b7d 100644 --- a/src/main/java/com/catchroom/ChatApplication.java +++ b/src/main/java/com/catchroom/ChatApplication.java @@ -1,5 +1,7 @@ package com.catchroom; +import jakarta.annotation.PostConstruct; +import java.util.TimeZone; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; @@ -7,6 +9,11 @@ @EnableFeignClients @SpringBootApplication public class ChatApplication { + // Bean 생명주기를 이용한 timezone 설정 + @PostConstruct + public void started() { + TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); + } public static void main(String[] args) { SpringApplication.run(ChatApplication.class, args); diff --git a/src/main/java/com/catchroom/chat/global/config/RedisConfig.java b/src/main/java/com/catchroom/chat/global/config/RedisConfig.java index b91a275..a6097c3 100644 --- a/src/main/java/com/catchroom/chat/global/config/RedisConfig.java +++ b/src/main/java/com/catchroom/chat/global/config/RedisConfig.java @@ -38,27 +38,43 @@ public RedisConnectionFactory redisConnectionFactory() { } /** - * redis에 발행(publish)된 메시지 처리를 위한 리스너 설정 + * redis 에 발행(publish)된 메시지 처리를 위한 리스너 설정 */ @Bean - public RedisMessageListenerContainer redisMessageListener( - MessageListenerAdapter listenerAdapter, + public RedisMessageListenerContainer redisMessageListener ( + MessageListenerAdapter listenerAdapterChatMessage, ChannelTopic channelTopic ) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(redisConnectionFactory()); - container.addMessageListener(listenerAdapter, channelTopic); + container.addMessageListener(listenerAdapterChatMessage, channelTopic); return container; } - /** - * 실제 메시지를 처리하는 subscriber 설정 추가 - */ + /** 실제 메시지를 처리하는 subscriber 설정 추가*/ @Bean - public MessageListenerAdapter listenerAdapter(RedisSubscriber subscriber) { + public MessageListenerAdapter listenerAdapterChatMessage(RedisSubscriber subscriber) { return new MessageListenerAdapter(subscriber, "sendMessage"); } + @Bean + public RedisMessageListenerContainer redisMessageListenerRoomList ( + MessageListenerAdapter listenerAdapterChatRoomList, + ChannelTopic channelTopic + ) { + RedisMessageListenerContainer container = new RedisMessageListenerContainer(); + container.setConnectionFactory(redisConnectionFactory()); + container.addMessageListener(listenerAdapterChatRoomList, channelTopic); + return container; + } + + + /** 실제 메시지 방을 처리하는 subscriber 설정 추가*/ + @Bean + public MessageListenerAdapter listenerAdapterChatRoomList(RedisSubscriber subscriber) { + return new MessageListenerAdapter(subscriber, "sendRoomList"); + } + /** * 어플리케이션에서 사용할 redisTemplate 설정 */ diff --git a/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java b/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java index 20fd8ed..7c13601 100644 --- a/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java +++ b/src/main/java/com/catchroom/chat/global/pubsub/RedisSubscriber.java @@ -21,7 +21,7 @@ public class RedisSubscriber { */ public void sendMessage(String publishMessage) { try { - log.info("RedisSubcriber publishMsg: {}", publishMessage); + log.info("Redis Subcriber publishMsg: {}", publishMessage); // ChatMessage 객채로 맵핑 ChatMessageDto chatMessage = objectMapper.readValue(publishMessage, ChatMessageDto.class); @@ -32,5 +32,18 @@ public void sendMessage(String publishMessage) { log.error("Exception {}", e); } } + + public void sendRoomList(String message) { + try { + log.info("Redis Subcriber room publishMsg: {}", message); + // ChatMessage 객채로 맵핑 + ChatMessageDto chatMessage = objectMapper.readValue(message, ChatMessageDto.class); +// chatMessage.setMessage("메세지를 보냈습니다!"); + // 채팅방을 구독한 클라이언트에게 메시지 발송 + messagingTemplate.convertAndSend("/sub/chat/room/999cf498-bba9-43d9-9b00-d363aca2e288", chatMessage); + } catch (Exception e) { + log.error("Exception {}", e); + } + } }