Hey everyone, running into a weird issue with the Notification API. I’ve got a Node.js service that subscribes to /api/v2/analytics/queues/realtime events via WebSocket. The goal is to pump these events into a local Kafka topic for downstream processing.
Everything works fine for about 15-20 minutes. Then the connection just drops. No error event fires on the socket, it just closes cleanly with code 1001 (Going Away). I’m using the ws library and handling reconnections, but the frequency is high enough that I’m losing data points.
Here’s the basic setup:
const WebSocket = require('ws');
const { Kafka } = require('kafkajs');
const kafka = new Kafka({
clientId: 'genesys-consumer',
brokers: ['localhost:9092']
});
const producer = kafka.producer();
async function startConsumer() {
await producer.connect();
const ws = new WebSocket(`wss://api.mypurecloud.com/api/v2/analytics/queues/realtime`, {
headers: {
'Authorization': `Bearer ${process.env.GENESYS_TOKEN}`
}
});
ws.on('open', () => {
console.log('Connected to Genesys Notification API');
});
ws.on('message', async (data) => {
try {
const event = JSON.parse(data);
// Check if it's a subscription confirm or actual data
if (event.type === 'subscription') return;
await producer.send({
topic: 'genesys-queue-events',
messages: [{ value: JSON.stringify(event) }]
});
console.log('Sent to Kafka');
} catch (err) {
console.error('Kafka send failed:', err);
}
});
ws.on('close', (code, reason) => {
console.log(`Socket closed: ${code} - ${reason}`);
// Reconnect logic here...
});
}
The docs mention a keep-alive mechanism, but I’m not sure if ws handles the specific Genesys ping/pong requirements automatically. I’ve tried sending manual pings, but that didn’t help. Is there a specific header I need to set or a configuration on the Genesys side for long-lived WebSocket connections? Or am I handling the reconnection wrong?