Closed wzgl998877 closed 4 months ago
My code is as follows `@Slf4j public class DianPingWebSocketClient extends WebSocketClient { @Autowired private IDianPingMessageHandle dianPingMessageHandle;
public DianPingWebSocketClient(URI serverUri) { super(serverUri); } @Override public void onOpen(ServerHandshake serverHandshake) { log.info("成功连接到大众点评websocket"); } @SneakyThrows @Override public void onMessage(String message) { log.info("接收到大众点评消息:{}", message); ServerMessage serverMessage = JsonUtils.toBean(message, ServerMessage.class); ClientMessage clientMessage = new ClientMessage(serverMessage.getMsg_id(), serverMessage.getType(), "ack"); dianPingMessageHandle.handleMessage(serverMessage); send(JsonUtils.toJson(clientMessage)); } @Override public void onClose(int code, String reason, boolean remote) { log.error("大众点评websocket断开连接,原因:{}", code); reconnect(); } @Override public void onError(Exception ex) { log.error("大众点评websocket连接异常:", ex); }
}` I'm thinking now, as a client, how should I handle reconnection?
I normally trigger a worker to reconnect, when I receive a onClose.
My code is as follows `@Slf4j public class DianPingWebSocketClient extends WebSocketClient { @Autowired private IDianPingMessageHandle dianPingMessageHandle;
}` I'm thinking now, as a client, how should I handle reconnection?