nsqjs
nsqjs copied to clipboard
Auto reconnect if writer failed to connect to NSQ
Once it is disconnected from NSQ(Manually kill the NSQ server), the 'closed' event has been triggered in the writer. Then start NSQ server, again. But writer failed to reconnect the server. It throws following error
2015-04-20T10:35:58.359Z - error: Error: No active Writer connection to send messages
at Writer.publish (/Users/guest/myserver/node_modules/nsqjs/lib/writer.js:99:13)
It will be great if you have auto reconnect in the Writer. Is there any other method to do it?
Is there any update about this issue and do you accept a PR for this one? I think this feature would be handy.
I think it's worth addressing since it's a common concern. I'll hopefully get to it soon.
Is there any update on this issue? In production, it becomes very critical. Application gets hanged and not responding to any requests. Even in development, writer gets closed if machine went to sleep.
I'll work on a solution today. As a workaround, you can listen for the close event and then reconnect. It's not elegant but it will work. That's effectively what the implementation will be within the Reader.
Thanks @dudleycarr. Currently i just did worst workaround of process.exit
and make supervisord
start the node server again. I will try with reconnect and looking for your solution :+1:
@dudleycarr is there any update on this issue?
Just to add, I also believe it would be a useful addition (to both Reader and Writer). I worked around it manually for now by wrapping the nsqjs library.
As a workaround it is possible to use https://www.npmjs.com/package/retry to reconnect. It is easy to set listener for closed
event and stop messages to be published while reconnecting. The tricky part is to buffer incoming messages during reconnection.
Any chance to have it landed soon? /cc: @dudleycarr
I'm also facing same problems here:
[0] Writer closed
[0] events.js:154
[0] throw er; // Unhandled 'error' event
[0] ^
[0]
[0] Error: read ECONNRESET
[0] at exports._errnoException (util.js:856:11)
[0] at TCP.onread (net.js:546:26)
@oaleynik this retry project is real nice, thanks for the tip. Only missing now is buffer the incoming messages as you just mentioned! 👍
@dudleycarr when resolve this issue?
bump
Happens to me too
There is a wrapper npm that provide auto-reconnection. https://github.com/Wiredcraft/nsq-strategies#nsqd-connection