package cn.flightfeather.supervision.socket.config
|
|
import cn.flightfeather.supervision.scheduler.ScheduleService
|
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Configuration
|
import org.springframework.scheduling.TaskScheduler
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
|
import org.springframework.web.socket.config.annotation.EnableWebSocket
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
|
import javax.annotation.Nullable
|
|
/**
|
*
|
* @date 2024/7/19
|
* @author feiyu02
|
*/
|
@Configuration
|
@EnableWebSocket
|
class WebSocketConfig(
|
private val handler: SPTextWebSocketHandler,
|
private val wsHandshakeInterceptor: WsHandshakeInterceptor
|
) : WebSocketConfigurer {
|
|
override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) {
|
registry
|
.addHandler(handler, "workstream")
|
.addInterceptors(wsHandshakeInterceptor)
|
.setAllowedOrigins("*")
|
}
|
|
/**
|
* webSocket定时器配置,解决同步使用定时器[ScheduleService]时的冲突问题
|
*/
|
@Bean
|
@Nullable
|
fun taskScheduler():TaskScheduler {
|
return ThreadPoolTaskScheduler().apply {
|
setThreadNamePrefix("SockJS-")
|
poolSize = Runtime.getRuntime().availableProcessors()
|
isRemoveOnCancelPolicy = true
|
}
|
}
|
}
|