Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 带弹簧5的反应式WebSocket-如何获取初始消息_Java_Spring_Websocket_Reactive Programming - Fatal编程技术网

Java 带弹簧5的反应式WebSocket-如何获取初始消息

Java 带弹簧5的反应式WebSocket-如何获取初始消息,java,spring,websocket,reactive-programming,Java,Spring,Websocket,Reactive Programming,我遵循了该教程(特别是带有浏览器WebSocket客户端的部分): 一切正常 我想更进一步,让我的处理程序根据客户端发送的参数进行操作。连接时,客户端正在发送消息(“来自浏览器的事件”): 我试图在服务器端(java)检索该消息: @覆盖 公共单声道句柄(WebSocketSession WebSocketSession){ webSocketSession.receive().handle((pWebSocketMessage,pSynchronousSink)->System.out.pri

我遵循了该教程(特别是带有浏览器WebSocket客户端的部分): 一切正常

我想更进一步,让我的处理程序根据客户端发送的参数进行操作。连接时,客户端正在发送消息(“来自浏览器的事件”):

我试图在服务器端(java)检索该消息:

@覆盖
公共单声道句柄(WebSocketSession WebSocketSession){
webSocketSession.receive().handle((pWebSocketMessage,pSynchronousSink)->System.out.println(pWebSocketMessage.getPayloadAsText());
返回webSocketSession.send(Flux.fromStream(Stream.generate(()->getData()))
.延迟要素(持续时间:百万(50))
.map(webSocketSession::textMessage))
.和(webSocketSession.receive()
.map(WebSocketMessage::getPayloadAsText)
.log());
}
但它不起作用


有什么想法吗?我做错了什么?

我也有同样的问题。我相信这可能会影响Spring Boot auto导入的模块,特别是Tomcat

我观看了这段视频,websockets立即使用了一堆:

  • 内蒂(不是雄猫)
  • Spring Boot 2.0.x<代码>Spring Boot starter父级
  • 弹簧集成
    Spring启动机集成
  • 弹簧WebFlux(反应式)
    Spring引导启动器WebFlux

排除tomcat依赖项(并改用netty)将有效:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- Exclude the Tomcat dependency -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
@Override
public Mono<Void> handle(WebSocketSession webSocketSession) {

   webSocketSession.receive().handle((pWebSocketMessage, pSynchronousSink) -> System.out.println(pWebSocketMessage.getPayloadAsText()));

   return webSocketSession.send(Flux.fromStream(Stream.generate(() -> getData()))
         .delayElements(Duration.ofMillis(50))
         .map(webSocketSession::textMessage))
         .and(webSocketSession.receive()
               .map(WebSocketMessage::getPayloadAsText)
               .log());
}
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- Exclude the Tomcat dependency -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>