Socket closed abruptly during opening handshake while trying to connect to RabbitMq

Viewed 251

I have a simple NodeJs application that should connect to RabbitMq.

The code:

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

Then run a RabbitMq image with:

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

  • I can access the rabbitmq and connect with the credentials user/password at http://localhost:5672.

For some reason, I have the error:

/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)
1 Answers

i see this is not likely the case as your using the correct port, however I was getting the exact same error messages when I tried using HTTP port instead of tpc port.

Again I know this isnt your issue but if guess it could help you pinpoint potential failpoints.

Related