Armenia
Armenia

Reputation: 97

Configuring socket timeout on amqplib connect in nodejs

If the RabbitMQ instance if found error then it takes about 120 seconds to timeout before trying to the error

Here is my code used for connecting:

         async function connectAmqp() {
            try {
                // Create amqp connection and is there any error then exit with error.
                cluster = await amqp.connect(`amqp://127.0.0.1:5672`,{
                    timeout:2000
                });
                return cluster;
            } catch (error) {
                throw error;
            }
        }

Upvotes: 1

Views: 786

Answers (1)

Satya S
Satya S

Reputation: 238

Assuming you are using amqplib.

The second argument takes the timeout value.

It was added in this PR

const amqp = require('amqplib');

const connection = await amqp.connect('amqp://localhost', {
  timeout: 2000,
});

Upvotes: 1

Related Questions