Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#noissue when the notifications message processing takes long time (few seconds up to 1 minute) PONG responses can be delayed as the socket is blocked, apply workaround in the TooTallNate client to address this issue #127

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

Expand Down