L
L
legacy_js2021-05-04 15:19:46
Node.js
legacy_js, 2021-05-04 15:19:46

Is it necessary to close the connection in rabbitmq?

Just started to get acquainted with rabbitmq, looked at examples from off site

Finally close the connection and exit

setTimeout(function() {
  connection.close();
  process.exit(0)
  }, 500);


my example code

const express = require('express');
const app = express();
const amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(error0, connection) {
    if (error0) {
        throw error0;
    }
    connection.createChannel(function(error1, channel) {
        if (error1) {
            throw error1;
        }

        channel.assertQueue('ses', {
            durable: false
        });

        app.get('/serv1',async (req, res) => {
            const data = {
                name: 'name',
                server: '3009',
            }

            await channel.sendToQueue("ses", Buffer.from(JSON.stringify(data)))
            // res.send(data)
        })

        app.listen(3009, () => {
            console.log('server start')
        })
    });
});


For example, I send a request through Postman, then everything arrives successfully and I receive a message, but if I insert the code above, then when I send a second request, I get an error, I understand why this error occurs, but I still can’t understand why close the connection?

In my understanding, if you listen to the port
app.listen(3009, () => {
            console.log('server start')
        })
then why close it, or am I doing something wrong, help me figure it out!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2021-05-04
@dimonchik2013

it is not necessary to close them,
Rabbit will close them himself, crashing when exceeded in the default settings,
well, or the newly opened ones will not be lucky: they didn’t fall, but new ones are not created or accepted,
you still need to sort out the concept and concepts of what you are doing, look at the logs, monitor look, look at
the lost messages - and understanding will come

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question