首页 > 解决方案 > 如何处理异步类型任务的ack

问题描述

现在我有一个 RabbitMQ 队列设置,我有几个工作人员正在监听推送到这个队列的事件。

这些事件本质上是字符串 url(例如,“ https://www.youtube.com ”),它将通过 puppeteer 进行处理。

我想知道的是,puppeteer 是异步的,一旦我完成了所有异步的东西,有没有办法让我返回一个 ack。

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

编辑——下面的代码是我在consumerabbitmq部分中所称的。因为这是异步的,所以它只是通过了这个操作并立即响应。

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

标签: node.jsrabbitmq

解决方案


推荐阅读