D
D
Dmitry Bychkov2020-12-19 17:58:37
Node.js
Dmitry Bychkov, 2020-12-19 17:58:37

MicroMQ and RabbitMQ request queue inside a service?

I have a "Browser" service that parses a page. You send him a url, he returns information about what kind of page it is, title, description, and so on.

The problem is when the service crashes. Another microservice continues to send tasks to it even at the moment when the Browser service is restarted. He gets a bunch of identical tasks and tightly hangs the system.

How to organize a queue inside a microservice so that it becomes single threaded, for example? And he processed 1 task, and the rest simply lay in the queue.

service

const app = new MicroMQ({
    name: serviceName, //browser - serviceName
    rabbit: {
        url: rabbitHost,
    }
});
app.post('/tools/urls_info', async function (request, response) {
        let { urls } = request.body;
        let urls_info = [];
        for(const url of urls){
            let info = await browser(url);
            urls_info.push(info)
        }
        response.json({result: true, array: urls_info});
    });
app.start()


This is how I send data to the service - browser
let {responce} = await app.ask('browser', {
            path: '/tools/urls_info',
            method: 'post',
            body: {
                urls: urls_array
            }
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-12-20
@bychkov_64

I would like to understand what it means

tightly hangs the system.
in the context of microservices? And why is this a problem?
He gets a bunch of the same tasks
Why is it necessary to process the same URLs repeatedly?
If, of course, it is strongly necessary, then you can check in the K / V storage for the presence of a key with such a URL that has a limited lifetime. Then, when the event occurs again, just ignore it.
Well, in general, the "Browser" microservice can only work as a queue handler, receiving messages sent by the REST API. It’s easy to add the URL scan results to the DBMS at your own pace, and the REST API will check for availability in the same DBMS and report the results to the client if ready.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question