Start receiving messages after WebSocket session established
@@ -40,6 +40,7 @@ import org.apache.pulsar.common.util.DateFormatter;
import org.apache.pulsar.common.util.ObjectMapperFactory;
import org.apache.pulsar.websocket.data.ConsumerAck;
import org.apache.pulsar.websocket.data.ConsumerMessage;
+import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import org.slf4j.Logger;
@@ -91,7 +92,6 @@ public class ConsumerHandler extends AbstractWebSocketHandler {
log.warn("[{}:{}] Failed to add consumer handler for topic {}", request.getRemoteAddr(),
request.getRemotePort(), topic);
}
- receiveMessage();
} catch (Exception e) {
log.warn("[{}:{}] Failed in creating subscription {} on topic {}", request.getRemoteAddr(),
request.getRemotePort(), subscription, topic, e);
@@ -167,6 +167,12 @@ public class ConsumerHandler extends AbstractWebSocketHandler {
});
}
+ @Override
+ public void onWebSocketConnect(Session session) {
+ super.onWebSocketConnect(session);
+ receiveMessage();
+ }
+
@Override
public void onWebSocketText(String message) {
super.onWebSocketText(message);
