如何为Wildfly服务器内部的WebSocket创建独立的tyrus客户端,以在两个Wildfly实例之间进行通信

问题描述 投票:1回答:1
  1. 尝试在两个不同的wildfly实例上的两个单独的可部署的战争之间建立Websocket连接。
  2. 使用tyrus-standalone-client建立与另一场战争的websocket连接。

  3. 以下是用于建立网络套接字连接的代码段

问题:是否可以将websocket连接到另一个可展开的战争? 我在运行时找不到任何异常,甚至找不到101-404错误(握手错误)。

    AuthConfig authConfig = AuthConfig.Builder.create().disableProvidedDigestAuth().build();
    Credentials credentials = new Credentials("root", "xyz");
    ClientManager client = ClientManager.createClient();
    client.getProperties().put(ClientProperties.AUTH_CONFIG, authConfig);
    client.getProperties().put(ClientProperties.CREDENTIALS, credentials);


    try (Session session = client.connectToServer(GovernorNodeWebSocketClient.class, new URI("ws://10.203.67.168:8080/xyz"))) {

        session.getBasicRemote().sendObject("xyz");
        System.out.println("4sendMessageToRemoteGovernor :: sent the message from device services to the remote governor"+responseObject.getJson());
    }
    catch (Exception e) {

        e.printStackTrace();
    }
java websocket glassfish wildfly-8
1个回答
1
投票

是的,当删除凭据部分和ClientManager.createClient()之后,在以下代码段中使用时,它是可能的;

因此,通过在您的wildfly实例上添加tyrus依赖项,我们可以在它们之间设置websocket连接

try  {
        System.out.println("sendMessageToRemoteGovernor :: "+message.getJson());
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        session = container.connectToServer(XYZ.class, new URI("ws://localhost:8080/xyz/xyz"));
        session.getBasicRemote().sendObject(message);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
© www.soinside.com 2019 - 2024. All rights reserved.