nodece commented on code in PR #19203:
URL: https://github.com/apache/pulsar/pull/19203#discussion_r1069074358


##########
pulsar-websocket/src/main/java/org/apache/pulsar/websocket/AbstractWebSocketHandler.java:
##########
@@ -172,6 +174,16 @@ protected static String getErrorMessage(Exception e) {
     @Override
     public void onWebSocketConnect(Session session) {
         super.onWebSocketConnect(session);
+        int webSocketPingDurationSeconds = 
service.getWebSocketProxyConfig().getWebSocketPingDurationSeconds();
+        if (webSocketPingDurationSeconds > 0) {
+            service.getExecutor().scheduleAtFixedRate(() -> {
+                try {
+                    
session.getRemote().sendPing(ByteBuffer.wrap("PING".getBytes()));
+                } catch (IOException e) {
+                    log.warn("[{}] WebSocket send ping", 
getSession().getRemoteAddress(), e);
+                }
+            }, 0, webSocketPingDurationSeconds, TimeUnit.SECONDS);

Review Comment:
   Good catch! 



##########
pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketProxyConfiguration.java:
##########
@@ -161,6 +161,9 @@ public class WebSocketProxyConfiguration implements 
PulsarConfiguration {
     @FieldContext(doc = "Timeout of idling WebSocket session (in 
milliseconds)")
     private int webSocketSessionIdleTimeoutMillis = 300000;
 
+    @FieldContext(doc = "Interval of time to sending the ping to keep alive")
+    private int webSocketPingDurationSeconds = -1;

Review Comment:
   Right.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to