[英]how to create standalone tyrus client for websockets inside the wildfly server to communicate between two wildfly instances
Using tyrus-standalone-client to make websocket connection to the another war. 使用tyrus-standalone-client建立与另一场战争的websocket连接。
Below is the snippet used to make web-socket connection 以下是用于建立网络套接字连接的代码段
Question : Could be it possible to make the websocket connection to another deployable war ? 问题:是否可以将websocket连接到另一个可展开的战争? I couldnt find any exceptions when I ran and not even 101-404 errors (Handshake Errors).
我在运行时找不到任何异常,甚至找不到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();
}
Yes its possible when I used below snippets, after removing credentials part and ClientManager.createClient(); 是的,当删除凭据部分和ClientManager.createClient()之后,在以下代码段中使用时,它是可能的;
So by adding the tyrus dependencies over your wildfly instance we can setup websocket connection between them 因此,通过在您的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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.