问题描述
我有这个简单的方法,它侦听Redis发布/订阅消息并发出服务器发送的事件,但由于某种原因,它不起作用。这就是我所拥有的。
@GetMapping
fun getNotifications(@RequestParam(name = "token",required = true) token: String): Flux<ServerSentEvent<Notification>> {
if (token.trim().isEmpty()) {
return Flux.error(ResponseStatusException(HttpStatus.UNAUTHORIZED,"Invalid token"))
}
val claims = jwtService.getAllClaimsFromToken(token) ?: return Flux.error(ResponseStatusException(HttpStatus.UNAUTHORIZED,"Invalid token"))
val userName = jwtService.getUsernameFromToken(claims) ?: return Flux.error(ResponseStatusException(HttpStatus.UNAUTHORIZED,"Invalid token"))
return userRepository.findOneByEmail(userName)
.filter { user -> checkAccess(user) }
.thenMany<ServerSentEvent<Notification>> {
notificationService.subscribe()
.map { ServerSentEvent.builder<Notification>()
.event("notification")
.data(it)
.build()
}.asFlux()
}.switchIfEmpty {
Flux.error<ResponseStatusException>(ResponseStatusException(HttpStatus.UNAUTHORIZED,"Token expired"))
}
}
private fun checkAccess(user: User): Boolean {
if (!user.enabled || !user.account.enabled) {
return false
}
/// More checking... logic
return true
}
有什么我想念的吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)