admin管理员组文章数量:1356768
I am writing producer & consumer using rabbitMq node-amqplib library, I am afraid about suddenly to lost connection of server , How could I check whether the connection is alive or not ?
I am writing producer & consumer using rabbitMq node-amqplib library, I am afraid about suddenly to lost connection of server , How could I check whether the connection is alive or not ?
Share Improve this question asked Apr 30, 2018 at 10:10 mayurmayur 1171 gold badge1 silver badge7 bronze badges 1- Connect with RabbitMQ Web UI Server. You can achieve this with the plugin. This might help: rabbitmq./management.html There you can see bindings between producer & consumer. – Zhivko.Kostadinov Commented Apr 30, 2018 at 10:32
2 Answers
Reset to default 4AMQP 0-9-1 offers a heartbeat feature to ensure that the application layer promptly finds out about disrupted connections (and also pletely unresponsive peers).
In amqplib you only need to set a heartbeat timeout (non 0) when you call connect([url, [socketOptions]])
and the check will be performed automatically.
More info here:
https://www.squaremobius/amqp.node/channel_api.html#heartbeating
http://www.rabbitmq./heartbeats.html
There are some options in doing this:
One way is using the heartbeat and an event listener, something like
conn.on('close', (err) => { this.connected = false; } )
Or you can get into the connection object. There is a risk here as upgrades to amqplib may break this, as it's not part of the official interface:
const connClosed = conn.connection['expectSocketClose']
There are other properties inside the connection object that also can tell you if it's closed, like stream writeable state (could be a false flag) or the heartbeater object.
本文标签:
版权声明:本文标题:javascript - How to check whether the connection is alive or not in RabbitMq node-amqplib library? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743968471a2570324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论