有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在Spring中还有哪些WebsocketClient实现?

我有一个连接到websocket端点的Spring应用程序。为此,我使用Spring StandardWebSocketClient类

WebSocketClient transport = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
String url = "ws://localhost:8080/asynccontrol";
StompSessionHandler handler = new MySessionHandler();
stompClient.connect(url, handler);

这在码头工作没有任何问题。现在我必须在WebSphereJRE7环境中部署这个应用程序。因为这个WAS版本不支持JSR-356,所以我必须使用另一个实现。从这个linkWebsocketClient可以是以下类型:

  • JSR-356运行时中的StandardWebSocketClient
  • 使用Jetty 9+原生WebSocket API的JettyWebSocketClient
  • Spring的WebSocketClient的任何实现

第一个选项不可用(没有JSR-356运行时),第二个选项不可用(需要JRE8,获取不支持的major.minor版本52),第三个选项是什么?Spring的WebSocketClient的其他实现是什么

也许可以重新编译组织。日食码头。JRE7中的websocketclient

解决方案

我不能使用jetty9。2,因为它与JettyWebSocketClient适配器不兼容。但是,我可能只使用不带适配器的api,使用StandardWebSocketClient

我安装了tomcat8,它也可以与StandardWebSocketClient一起使用。在tomcat7中,我仍然收到不兼容的WsContainerProvider子类型错误,可能是我特定tomcat版本的错误。对于备份计划,我还开发了TyrusWebSocketClient。谢谢你们


共 (1) 个答案

  1. # 1 楼答案

    您可以使用tyrus-standalone client

    如果您使用的是Maven,请添加此依赖项:

    <dependency>
         <groupId>org.glassfish.tyrus.bundles</groupId>
         <artifactId>tyrus-standalone-client</artifactId>
         <version>1.9</version>
    </dependency>
    

     <dependency>
         <groupId>org.glassfish.tyrus.bundles</groupId>
         <artifactId>websocket-ri-bundle</artifactId>
         <version>1.2.1</version>
     </dependency>
    

    我使用了websocket-ri-bundle(第二个依赖项)它可以工作,但是这两个依赖项中的任何一个都可以工作

    编辑

    如果您看到StandardWebsocketClient

    public StandardWebSocketClient() {
        this.webSocketContainer = ContainerProvider.getWebSocketContainer();
    }
    

    Spring试图从客户机实现的META-INF/services/javax.websocket.ContainerProvider文件中识别容器提供程序。因此,任何正确指出该文件的websocket客户端实现都可以工作