- 我想订阅/topic/greetings。我如何在邮递员中使用原始方法和socket.io 做到这一点?
- 还有其他替代方法可以在本地测试 websocket 吗?
我的代码来自这里。Spring Boot 入门 websocket 应用程序 https://spring.io/guides/gs/messaging-stomp-websocket/
唯一的区别是我的 WS 配置类。
我在邮递员中连接到 websocket:ws://localhost:8080/greetings然后我真的不知道我应该做什么。
package com.example.messagingstompwebsocket;
import org.springframework.context.annotation.Configuration;
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 configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
registry.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/greetings");
registry.addEndpoint("/gs-guide-websocket").withSockJS();
}
}
您可以使用此网站在本地测试网络套接字:http://jxy.me/websocket-debug-tool/ http://jxy.me/websocket-debug-tool/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)