-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Feat/#452] 이벤트 라이브러리 구현 #463
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring Context에 있는 이벤트를 한번 감쌌다고 생각하시면 될 것 같습니다.
저는 코드 작성, 테스트, 주석을 적으며 어느정도 익숙해져 버려서 혹시 보시면서 이거 왜??? 이런 생각이 드시는 부분이 있으면 코멘트 남겨주시면 반영하겠슴다!
|
||
@Async | ||
@EventListener | ||
open fun onApplicationEvent(message: Message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 메시지를 받습니다.
messageReverseRelays.forEach { relay -> | ||
relay.javaClass.methods | ||
.filter { it.name.equals("onApplicationEvent") && it.isForLocalMessageReverseRelay() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocalMessageReverseRelay
타입의 MessageReverseRelay
를 필터링 합니다.
val messageType = method.messageType() | ||
method.getAnnotation(LocalSubscribeMessage::class.java).topic.let { | ||
if (!method.name.contains(it)) { | ||
return@forEach | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocalSubscribeMessage
에서 설정한 토픽과 message로 알 수 있는 topic이 다르면 종료합니다.
objectMapper.writeValueAsString(message.payload).let { payload -> | ||
objectMapper.readValue(payload, MessagePayload::class.java)?.let { messagePayload -> | ||
objectMapper.convertValue(messagePayload, messageType).let { relayMessage -> | ||
log.info { | ||
"[${Thread.currentThread().name}] Publish message to ${relay.javaClass.simpleName}: $relayMessage" | ||
} | ||
method.invoke(relay, relayMessage) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message를 LocalMessageReverseRelay
가 받을 수 있는 객체로 바꾼 후 LocalSubscribeMessage
의 onApplicationEvent
에 전달해 줍니다.
@Bean | ||
fun localMessageBeanPostProcessor( | ||
objectMapper: ObjectMapper, | ||
messageReverseRelays: List<MessageReverseRelay<*>>, | ||
): BeanFactoryPostProcessor = | ||
BeanFactoryPostProcessor { beanFactory -> | ||
beanFactory.beanDefinitionNames | ||
.filter { | ||
it.contains("Local", ignoreCase = true) && | ||
it.contains( | ||
"MessageReverseRelay", | ||
ignoreCase = true, | ||
) | ||
}.takeIf { it.isNotEmpty() } | ||
?.also { localReverseBeanNames -> | ||
log.info { "LocalReverse Beans are found: ${localReverseBeanNames.joinToString(", ")}" } | ||
beanFactory.registerSingleton( | ||
"localMessageBroadCaster", | ||
LocalMessageBroadCaster(objectMapper, messageReverseRelays), | ||
) | ||
log.info { "Local message broadcaster is registered" } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocalMessageReverseRelay
를 구현하였을 때만 localMessageBroadCaster
가 등록되도록 합니다.
if (!message.javaClass.name.contains(it, ignoreCase = true)) { | ||
return@forEach | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LocalSubscribeMessage에서 설정한 토픽과 message로 알 수 있는 topic이 다르면 종료합니다.
기존에 method로 되어 있는것 message로 수정
objectMapper.convertValue(message.payload, messageType).let { relayMessage -> | ||
log.info { "[${Thread.currentThread().name}] Publish message to ${relay.javaClass.simpleName}: $relayMessage" } | ||
method.invoke(relay, relayMessage) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message를 LocalMessageReverseRelay가 받을 수 있는 객체로 바꾼 후 LocalSubscribeMessage의 onApplicationEvent에 전달해 줍니다.
기존 불필요하게 수행하였던 message.payload -> json -> messagePayload 객체 과정 제거
🎫 연관 이슈
resolved: #452
💁♂️ PR 내용
🙏 작업
🙈 PR 참고 사항
📸 스크린샷
🚩 추가된 SQL 운영계 실행계획
🤖 테스트 체크리스트