diff --git a/notification2-examples/notification2-example-client/src/main/java/c8y/example/notification/client/websocket/tootallnate/TooTallNateWebSocketClient.java b/notification2-examples/notification2-example-client/src/main/java/c8y/example/notification/client/websocket/tootallnate/TooTallNateWebSocketClient.java index 547cb6809d..2315029ea6 100644 --- a/notification2-examples/notification2-example-client/src/main/java/c8y/example/notification/client/websocket/tootallnate/TooTallNateWebSocketClient.java +++ b/notification2-examples/notification2-example-client/src/main/java/c8y/example/notification/client/websocket/tootallnate/TooTallNateWebSocketClient.java @@ -4,6 +4,7 @@ import c8y.example.notification.client.websocket.NotificationCallback; import c8y.example.notification.client.websocket.WebSocketClient; import lombok.extern.slf4j.Slf4j; +import org.java_websocket.WebSocketImpl; import org.java_websocket.handshake.ServerHandshake; import java.net.URI; @@ -43,13 +44,23 @@ public void onOpen(ServerHandshake serverHandshake) { @Override public void onMessage(String message) { - Notification notification = Notification.parse(message); - this.callback.onNotification(notification); + try { + //Recommended workaround for client issue that can start disconnection if the PONG response are delayed because of busy socket (the RFC 6455 specification does not require the client to send Ping frames if it is constantly receiving messages from the server). + //((WebSocketImpl) getConnection()).updateLastPong(); + Notification notification = Notification.parse(message); + callback.onNotification(notification); + acknowledge(notification); + } catch (Throwable e) { + log.error("Error processing message '{}'. Acknowledge will not be sent so the message will be resent in the future.", message); + } + } + + private void acknowledge(final Notification notification) { if (notification.getAckHeader() != null) { // Best Practice: Acknowledge notifications as soon as possible. send(notification.getAckHeader()); // ack message } else { - throw new RuntimeException("No message id found for ack"); + log.error("Invalid message without ACK header, message will not be acknowledged"); } }