Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed creating two connections instead of one cause close event handl… #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ export default class RabbitMqQueue {
const {url, amqpOptions, reconnectDelaySecond} = this.options
try {
const connection = await amqplib.connect(url, amqpOptions)
connection.on('error', () => this.reconnect())
connection.on('close', () => this.reconnect())

let connectionRestoring = true;
connection.on('error', () => {
if (connectionRestoring) {
connectionRestoring = false
this.reconnect()
}
})
connection.on('close', () => {
if (connectionRestoring){
connectionRestoring = false
this.reconnect()
}
})

console.log('[RabbitMQ] Connection successful.')
this.connecting = false
Expand Down