fix(user-creator-chat): Redis pub/sub 고정 채널을 사용한다
This commit is contained in:
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import org.springframework.data.redis.connection.Message
|
||||
import org.springframework.data.redis.connection.MessageListener
|
||||
import org.springframework.data.redis.core.StringRedisTemplate
|
||||
import org.springframework.data.redis.listener.PatternTopic
|
||||
import org.springframework.data.redis.listener.ChannelTopic
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.socket.TextMessage
|
||||
@@ -19,7 +19,7 @@ class UserCreatorChatRoomMessageBroker(
|
||||
listenerContainer: RedisMessageListenerContainer
|
||||
) : MessageListener {
|
||||
init {
|
||||
listenerContainer.addMessageListener(this, PatternTopic("$ROOM_CHANNEL_PREFIX:*"))
|
||||
listenerContainer.addMessageListener(this, ChannelTopic(ROOM_CHANNEL))
|
||||
}
|
||||
|
||||
fun publish(roomId: Long, memberId: Long, payload: String) {
|
||||
@@ -28,7 +28,7 @@ class UserCreatorChatRoomMessageBroker(
|
||||
memberId = memberId,
|
||||
payload = payload
|
||||
)
|
||||
stringRedisTemplate.convertAndSend(roomChannel(roomId), objectMapper.writeValueAsString(message))
|
||||
stringRedisTemplate.convertAndSend(ROOM_CHANNEL, objectMapper.writeValueAsString(message))
|
||||
}
|
||||
|
||||
override fun onMessage(message: Message, pattern: ByteArray?) {
|
||||
@@ -50,11 +50,7 @@ class UserCreatorChatRoomMessageBroker(
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ROOM_CHANNEL_PREFIX = "v2:user-creator-chat:ws:room"
|
||||
|
||||
fun roomChannel(roomId: Long): String {
|
||||
return "$ROOM_CHANNEL_PREFIX:$roomId"
|
||||
}
|
||||
private const val ROOM_CHANNEL = "v2:user-creator-chat:ws:room"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user