I have a problem with PUB/SUB mode, where SUB sometimes randomly (once a day or so) stops receiving data. I wan to add some custom heartbeat message from PUB to SUB every second, but I have to send it from same thread because PUB is not thread safe. To do that I can use some java Timer/Scheduler to do it every second but problem is that Timer/Scheduler creates a new thread. I am receiving data from external websocket in PUB, and I do not see a way to send heartbeat everyone is talking about. Only way would be adding proxy using XPUB-XSUB...
Any idea how could it be done?
A :
Yes, several - before anything else, ZeroMQ has internal
.poll()-er, that can listen for socket-related events, not longer than there stated amount of[ms], so a private event-aware loop can be implemented this way ( be it using a stumpedinproc://voidPAIR-socketPAIR-archetype ( which bears indeed a Zero-overhead for not having any transport-class protocol / stack ) receivingOr using a this naive-enough structured, yet segmented control-loop. ZeroMQ can inject "job-ToDo-command"(s) into the control-loop, yet on no receiving any such real work command, the control-loop can
.send()a "soft"-heartbeat in due times, leaving customisable amounts of rest/sleep, re-.send() and its own "soft"-flagged termination signalling.Bear with me, this is indeed a "naive-enough"-DEMO running (live).