Skip to content

Create a way to detect channel close to be able to recreate the channel #40

@icastillejogomez

Description

@icastillejogomez

I had an issue when I ack some messages who come from a queue that was marked as non-ack. So calling basicAck or basicNack was throw an error.

This issue was solved and my system now is running as expected but was sad not found a way to detect channel close event to be able to recreate/reconnect that channel.

I have:

// Connect and create a channel to RabbitMQ
this.client = new AMQPClient(connectionUrl)
this.connection = await this.client.connect()
this.channel = await this.connection.channel()

this.client.onerror = (error) => {
    console.error(error)
    this.tryReconnect()
}

// Handle disconnection
this.connection.onerror = () => {
    console.error(
        `[RabbitMqClient] ${new Date().toISOString()} Upps! We have a connection error... Trying to reconnect with exponential backoff..`
    )
    this.tryReconnect()
}

But this only work when RabbitMQ server goes down not when the channel crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions