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 issue when reconnecting | channel is null #39

Merged
merged 1 commit into from
Feb 3, 2025
Merged
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
10 changes: 5 additions & 5 deletions src/messaging/rabbitmq/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ export default class RMQConsumer {
try {
const success = await this.processFn(msg.content.toString())
if (success === true) {
this.channel.ack(msg)
this.channel!.ack(msg)
console.log(`[Consumer ${this.name}]: Successfully processed message`)
} else {
this.channel.nack(msg, false, true)
this.channel!.nack(msg, false, true)
}
} catch (e) {
console.error(
`Consumer [${
this.name
}]: Error while processing message: ${e}\nMessage: ${msg.content.toString()}`
)
this.channel.nack(msg, false, true)
this.channel!.nack(msg, false, true)
}
}
})
Expand Down Expand Up @@ -104,14 +104,14 @@ export default class RMQConsumer {
if (!this.isConnected) {
const interval = setInterval(async () => {
attempt++
console.log(`[retryConnection ${this.name}]: (Attempt ${attempt}) intitiated connection retry...`)
console.log(`[retryConnection ${this.name}]: (Attempt ${attempt}) initiated connection retry...`)
try {
await this.consume()
console.log(`[retryConnection ${this.name}]: (Attempt ${attempt}) successfully connected...`)
this.isConnected = true
clearInterval(interval)
} catch (e) {
console.log(`[retryConnection ${this.name}]: (Attempt ${attempt}) unsuccessul. Err: ${e}`)
console.log(`[retryConnection ${this.name}]: (Attempt ${attempt}) unsuccessful. Err: ${e}`)
}
}, 5000) // Wait 5 seconds before retrying
}
Expand Down
Loading