I’m building a Node.js service to subscribe to streaming-analytics notifications and push them to a Kafka topic. The connection seems stable initially, but the WebSocket closes unexpectedly after about 10 minutes of inactivity on the specific queue being monitored. I’m using the standard ws library in Node v18.
Here’s the subscription setup:
const WebSocket = require('ws');
const ws = new WebSocket('wss://notify-eu.genesiscloud.com/v2/notifications');
ws.on('open', () => {
ws.send(JSON.stringify({
action: 'subscribe',
uri: '/v2/analytics/queue/realtime',
query: 'interval=PT5S&groupBy=queueId'
}));
});
ws.on('message', (data) => {
const event = JSON.parse(data);
if (event.type === 'streaming-analytics') {
// push to kafka
}
});
The bearer token is refreshed every 50 minutes, so auth isn’t the issue. I’m seeing a 1001 close code (Going Away) from the server, but no error payload in the WebSocket frames. The REST API for the same analytics query works fine with the same token.
I’ve tried adding a ping/pong handler to keep the connection alive:
ws.on('pong', () => console.log('pong received'));
setInterval(() => {
ws.ping();
}, 15000);
This helps for a bit, but the 1001 still happens. Is there a specific header or keep-alive mechanism required for the Notification API WebSocket that I’m missing? The docs mention X-Genesys-Request-Id for REST, but nothing for WebSocket persistence. Also, the streaming-analytics event payload sometimes includes a partial flag that I can’t find documented. Does that affect the subscription lifecycle? I’m stuck on why the server initiates the close without a clear reason in the logs.