如何处理异步类型任务的问题

时间:2018-05-05 21:45:50

标签: node.js rabbitmq

现在我有一个RabbitMQ队列设置,我有几个工作人员正在侦听推入此队列的事件。

事件本质上是字符串网址(例如,“https://www.youtube.com”),并且它将通过木偶操纵者进行处理。

我想知道木偶操作是异步的,有一种方法让我在完成所有异步操作后返回一个ack。

现在,我认为我的工作人员正在聆听队列,因为ack没有被解雇。

编辑 - 以下代码是我在rabbitmq的consume部分中调用的内容。因为这是异步的,所以它只是通过这个操作而且只是立刻回应。

    (async () => {
    const args = {
        evaluatePage: (() => ({
            title: $('title').text(),
        })),
        persistCache: true,
        cache,
        onSuccess: (result => {
            console.log('value for result -- ', result.result.title);
        }),
    };

    // we need to first setup the crawler
    // then we can start sending information to it
    const crawler = await HCCrawler.launch(args);

    crawler.queue(urls);

    await crawler.onIdle();
    await crawler.close();
})();

0 个答案:

没有答案
相关问题