make my heartbeat
the readme says
on(event: 'heartbeat', listener: (lsn: string, timestamp: number, shouldRespond: boolean) => Promise<void> | void)A heartbeat check signal has been received from the server. You may need to run service.acknowledge().
Do I need to handle this event? Other than shouldRespond, when should I acknowledge or not? What happens if I don't acknowledge a heartbeat?
service.on("heartbeat", async (lsn, ts, shouldRespond) => {
if(shouldRespond) await service.acknowledge(lsn);
});
service.on("heartbeat", async (lsn, ts, shouldRespond) => { if(shouldRespond) await service.acknowledge(lsn); });
Just spent several hours tracking down why I was getting connection terminated unexpectedly, and this manual acknowledge in the heartbeat handler wound up being the fix. The acknowledge options in service instantiation appear to be meaningless, and this is basically undocumented, would be great if this was in the basic setup docs if it's intentionally required and not a bug.
The "auto" acknowledge options in service instantiation appears to ack the message after the "data" event is emitted. This took me a min to grok but the intent seems to be to proactively ack to PG once the event is considered handled. The ack that you are calling in the "heartbeat" event is called automatically if timeoutSeconds is not zero. If you have that config set to zero, then you need to manually ack the way you are doing it. I should point out that acking any LSN before you have persisted it to some durable storage is a recipe for losing messages. This could happen if your "data" handler is doing something async and you ack the processing LSN in "heartbeat" before that asyc call completes.