StompWebSocketConfig.java
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.huaheng.framework.config;
import com.huaheng.pc.stompwebsocket.SessionAuthHandshakeInterceptor;
import com.huaheng.pc.stompwebsocket.StompHandshakeHandler;
import com.huaheng.pc.stompwebsocket.WebsocketConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
@Configuration
@EnableWebSocketMessageBroker
public class StompWebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Autowired
private TaskScheduler messageBrokerTaskScheduler;
@Autowired
private SessionAuthHandshakeInterceptor sessionAuthHandshakeInterceptor;
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
// config.enableStompBrokerRelay(WebsocketConstants.BROKER_TOPIC, WebsocketConstants.BROKER_QUEUE);
config.enableSimpleBroker(WebsocketConstants.BROKER_TOPIC, WebsocketConstants.BROKER_QUEUE)
.setHeartbeatValue(WebsocketConstants.HEART_BEAT)
.setTaskScheduler(this.messageBrokerTaskScheduler);
config.setUserDestinationPrefix(WebsocketConstants.USER_PRIFIX);
config.setApplicationDestinationPrefixes(WebsocketConstants.APP_PRIFIX);
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint(WebsocketConstants.ENDPOINT)
.setHandshakeHandler(new StompHandshakeHandler())
.addInterceptors(sessionAuthHandshakeInterceptor)
.withSockJS();
}
}