The issue isn’t the Kafka producer timing out, it’s that the WebSocket connection to the Genesys Cloud notification service is dropping because the client isn’t handling the reconnection logic properly after a period of inactivity or network jitter. The NotificationClient in the Node SDK is stateful, and if the underlying socket closes without the SDK catching it, your subscription just hangs.
You need to listen to the close or error events on the client instance and manually restart the subscription. Also, make sure you’re using the correct scope analytics:read which you probably have, but it’s worth double checking if the token was refreshed correctly during that 3 minute window.
Here is a more resilient pattern for handling the subscription. You’ll want to wrap the subscribe call in a function that you can call again if the connection drops.
const PureCloudPlatformClientV2 = require('@genesyscloud/genesyscloud');
const client = new PureCloudPlatformClientV2.NotificationClient();
// Ensure you have initialized the client with valid credentials first
// PureCloudPlatformClientV2.PureCloudPlatformClientV2.init(...);
let isSubscribed = false;
function subscribeToNotifications() {
if (isSubscribed) return;
console.log('Attempting to subscribe to analytics notifications...');
const subscription = client.subscribe('/api/v2/analytics/notifications', (payload) => {
// Your existing Kafka producer logic
producer.send({
topic: 'genesys-analytics',
messages: [{ value: JSON.stringify(payload) }]
});
});
// Handle connection drops
client.on('close', () => {
console.warn('Notification client disconnected. Reconnecting...');
isSubscribed = false;
// Small delay before reconnecting to avoid hammering the API
setTimeout(subscribeToNotifications, 5000);
});
client.on('error', (err) => {
console.error('Notification client error:', err);
isSubscribed = false;
setTimeout(subscribeToNotifications, 5000);
});
isSubscribed = true;
}
// Initial call
subscribeToNotifications();
The key here is that client.on('close') fires when the WebSocket disconnects. If you don’t listen to it, your app thinks it’s still connected but it’s not. The 3 minute mark is likely when the Genesys Cloud server sends a ping/pong or closes idle connections, and your client isn’t responding or reconnecting.
Also, check your Kafka producer configuration. If you’re not setting ack: 'all' or similar, you might be losing messages silently if the broker is under load, but since you said the WebSocket ping dies, it’s definitely a connectivity issue on the Genesys side of the integration.
Make sure your environment variables for the Genesys client initialization are loaded before you start the subscription loop. If the token expires, the subscription will fail silently unless you handle the auth refresh separately. The SDK usually handles this, but it’s good to log it just in case.
One more thing, if you’re running this in a container or serverless environment, make sure the process doesn’t exit. Node.js won’t keep running just because of an open WebSocket unless you have something else keeping the event loop alive. If this is a long running service, add a simple keep alive interval or ensure your main process doesn’t terminate.
The reconnection logic above should fix the dropping payloads. If it still drops, check the Genesys Cloud API logs for any rate limiting errors on the notification endpoint, though that’s less likely to happen exactly at 180 seconds. It’s almost always the client side not handling the socket closure.