【问题标题】:Socket closed abruptly during opening handshake while trying to connect to RabbitMq在尝试连接到 RabbitMq 时打开握手期间套接字突然关闭
【发布时间】:2022-08-17 08:22:39
【问题描述】:

我有一个简单的NodeJs 应用程序,它应该连接到 RabbitMq。

编码:

const amqp = require(\'amqplib/callback_api\');

const amqpUri = \"amqp://user:password@localhost:5672\"
if (amqpUri == null)
    throw Error(\'Missing AMQP_URI environment variable.\');

amqp.connect(amqpUri, function(error0, connection) {
    if (error0)
        throw error0;

    connection.createChannel(function(error1, channel) {
        if (error1) {
            throw error1;
        }

        const exchangeName = \'product.event\';
        const queueName1 = \'create\';
        const routingKey1 = \'create\';
        const queueName2 = \'delete\';
        const routingKey2 = \'delete\';

        channel.assertExchange(exchangeName, \'topic\', {
            durable: false,
        });

        // create
        channel.assertQueue(queueName1, {
            durable: false,
        });
        channel.bindQueue(queueName1, exchangeName, routingKey1);
        channel.consume(queueName1, (msg) => consumeCreated(channel, msg));

        // delete
        channel.assertQueue(queueName2, {
            durable: false,
        });
        channel.bindQueue(queueName2, exchangeName, routingKey2);
        channel.consume(queueName2, (msg) => consumeDeleted(channel, msg));
    });
});

然后使用以下命令运行 RabbitMq 图像:

docker run -d --hostname my-rabbit --name some-rabbit -p 5672:15672 -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password rabbitmq:3-management

  • 我可以访问 rabbitmq 并使用凭据进行连接用户/密码http://localhost:5672

出于某种原因,我有错误:

/home/hamuto/CLO902-Group35/indexer/app.js:12
        throw error0;
        ^

Error: Socket closed abruptly during opening handshake
    at Socket.endWhileOpening (/home/hamuto/CLO902-Group35/indexer/node_modules/amqplib/lib/connection.js:260:17)
    at Socket.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

    标签: node.js rabbitmq


    【解决方案1】:

    我认为这不太可能是因为您使用了正确的端口,但是当我尝试使用 HTTP 端口而不是 tpc 端口时,我得到了完全相同的错误消息。

    我再次知道这不是您的问题,但如果猜测它可以帮助您查明潜在的故障点。

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 2019-07-19
      • 2013-07-04
      • 2020-10-24
      • 1970-01-01
      • 2017-03-03
      • 2014-09-18
      • 2012-08-12
      相关资源
      最近更新 更多