12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package com.steerinfo.dil.config;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.messaging.simp.config.ChannelRegistration;
- import org.springframework.messaging.simp.config.MessageBrokerRegistry;
- 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 WebSocketConfig implements WebSocketMessageBrokerConfigurer {
- @Override
- public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
- stompEndpointRegistry
- .addEndpoint("/webSocket")
- .setAllowedOrigins("*")
- .withSockJS(); //使用sockJS
- }
- @Override
- public void configureMessageBroker(MessageBrokerRegistry registry) {
- //这里使用的是内存模式,生产环境可以使用rabbitmq或者其他mq。
- //这里注册两个,主要是目的是将广播和队列分开。
- //registry.enableStompBrokerRelay().setRelayHost().setRelayPort() 其他方式
- registry.enableSimpleBroker("/topic");
- //设置客户端前缀 即@MessageMapping
- registry.setApplicationDestinationPrefixes("/app");
- //点对点发送前缀
- registry.setUserDestinationPrefix("/user");
- }
- /**
- * 输入通道参数配置
- *
- * @param registration
- */
- @Override
- public void configureClientInboundChannel(ChannelRegistration registration) {
- }
- }
|