在nodejs中的AMQPLIB连接上配置套接字超时

发布于 2025-01-27 19:28:14 字数 475 浏览 3 评论 0原文

如果RabbitMQ实例如果找到错误,则大约需要120秒才能超时,然后尝试错误,

这是我用于连接的代码:

         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;
            }
        }

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;
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜中书 2025-02-03 19:28:14

假设您正在使用amqplib

第二个参数为timeout值。

它在此

const amqp = require('amqplib');

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

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,
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文