From 9366b605e1346a1a96a932f2d59db26d6034a0ce Mon Sep 17 00:00:00 2001 From: sungjiwoon Date: Thu, 18 Jan 2024 11:38:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat=20:=20redis=20config,=20roomList=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/global/config/RedisConfig.java | 32 ++++++++++++++----- .../chat/global/pubsub/RedisSubscriber.java | 15 ++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) 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 efe955b..905eb77 100644 --- a/src/main/java/com/catchroom/chat/global/config/RedisConfig.java +++ b/src/main/java/com/catchroom/chat/global/config/RedisConfig.java @@ -44,27 +44,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); + } + } } From acde7c3563483d6d52443535d31b7de805fb83ea Mon Sep 17 00:00:00 2001 From: sungjiwoon Date: Thu, 18 Jan 2024 17:11:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix=20:=20=EC=8B=9C=EA=B0=84=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20->=20=ED=95=9C=EA=B5=AD=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/catchroom/ChatApplication.java | 7 +++++++ 1 file changed, 7 insertions(+) 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);