Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用StompClient在Spring WebSocket上传递消息时出错_Java_Spring_Websocket_Stomp_Spring Websocket - Fatal编程技术网

Java 使用StompClient在Spring WebSocket上传递消息时出错

Java 使用StompClient在Spring WebSocket上传递消息时出错,java,spring,websocket,stomp,spring-websocket,Java,Spring,Websocket,Stomp,Spring Websocket,我正在尝试向我的主题发送消息,但问题是当我发送消息时,什么都没有发生。。。我正在使用ApacheTomcat 7.0.53 更新:04/15:测试链接: 登录名:admin 密码:admin 访问TOMCAT日志的链接: Opening Web Socket... stomp.min.js:8 Web Socket Opened... stomp.min.js:8 >>> CONNECT accept-version:1.1,1.0 heart-beat:10000,1000

我正在尝试向我的主题发送消息,但问题是当我发送消息时,什么都没有发生。。。我正在使用ApacheTomcat 7.0.53

更新:04/15:测试链接:

登录名:admin

密码:admin

访问TOMCAT日志的链接:

Opening Web Socket... stomp.min.js:8
Web Socket Opened... stomp.min.js:8
>>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000

<<< CONNECTED
user-name:balbi
heart-beat:0,0
version:1.1

connected to server undefined stomp.min.js:8
User connected: balbi 
>>> SUBSCRIBE
id:sub-0
destination:/topic/greetings
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketApplicationContext extends AbstractWebSocketMessageBrokerConfigurer {

@Autowired
private Environment env;

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    if (env.acceptsProfiles("test.tomcat")) {
        registry.addEndpoint("/application")
                .setHandshakeHandler(
                        new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy()))
                .withSockJS();
    } else {
        registry.addEndpoint("/application").withSockJS();
    }
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableSimpleBroker("/queue/", "/topic/");
    registry.setApplicationDestinationPrefixes("/app");
}
}

附言:你需要选中侧边栏上的组合框来开始观看消息

Github链接:

日志:

代码:


当连接到您的应用程序时,我设法从JavaScript控制台向一个主题发送一条消息,并在网页中返回一条消息

var socket = new SockJS('/kupo/application');
var stompClient = Stomp.over(socket);
stompClient.send('/topic/greetings',{},"hello");
我收到:

<<< MESSAGE
subscription:sub-0
content-length:5
message-id:ts3oov6b-1
destination:/topic/greetings
content-length:5

hello 

您的浏览器控制台中是否有日志?您能在“网络”选项卡中看到websocket连接吗?完成,我已经包含了浏览器控制台日志。是否可以将github链接发布到代码中?您认为可以在github中发布问题的最小示例吗?对于整个应用程序,我无法运行它,它试图连接到数据库。同样在CializaoView.js中,问题代码似乎没有在应用程序中的任何地方使用。在您对配置文件的评论中,我已经修复了。日程安排很好。问题是当我需要从服务器向客户端发送消息时。我正在创建一个访问tomcat日志的链接。按照该链接从服务器访问de catalina.out:为org.springframework.messaging启用跟踪级别日志记录。然后,您可以跟踪服务器端的消息发生了什么。在我看来,“DefaultSubscriptionRegistry-为destination=/topic/greetings找到0个订阅”更可能是罪魁祸首。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketApplicationContext extends AbstractWebSocketMessageBrokerConfigurer {

@Autowired
private Environment env;

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    if (env.acceptsProfiles("test.tomcat")) {
        registry.addEndpoint("/application")
                .setHandshakeHandler(
                        new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy()))
                .withSockJS();
    } else {
        registry.addEndpoint("/application").withSockJS();
    }
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableSimpleBroker("/queue/", "/topic/");
    registry.setApplicationDestinationPrefixes("/app");
}
}
var socket = new SockJS('/kupo/application');
var stompClient = Stomp.over(socket);
stompClient.send('/topic/greetings',{},"hello");
<<< MESSAGE
subscription:sub-0
content-length:5
message-id:ts3oov6b-1
destination:/topic/greetings
content-length:5

hello