美文网首页
java webSocket

java webSocket

作者: Easy的幸福 | 来源:发表于2017-09-14 16:20 被阅读0次

importorg.springframework.context.annotation.Configuration;

importorg.springframework.messaging.simp.config.MessageBrokerRegistry;

importorg.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;

importorg.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;

importorg.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**

* Modified By :

*/

@Configuration

@EnableWebSocketMessageBroker

public classWebSocketConfigextendsAbstractWebSocketMessageBrokerConfigurer {

/**

* 注册Stomp节点,接受来自客户端的连接

*/

@Override

public voidregisterStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint("/webSocket").setAllowedOrigins("*").withSockJS();

}

/**

* 设置消息连接的各种规范信息

*/

@Override

public voidconfigureMessageBroker(MessageBrokerRegistry registry) {

//客户端订阅的地址

//to enable a simple memory-based message broker to carry the greeting messages

// back to the client on destinations prefixed with "/topic".

//创建一个监听的频道

registry.enableSimpleBroker("/topic");

}

}

在调用的类中引入

@Autowired

privateSimpMessagingTemplatetemplate;

相关文章

网友评论

      本文标题:java webSocket

      本文链接:https://www.haomeiwen.com/subject/ntmdsxtx.html