繁体   English   中英

无法在 nodeJS 中使用 rascal 将 subscribe.on(“message”) 的内容发送回被调用方方法

[英]Not able to send content of subscribe.on(“message”) back to callee methods using rascal in nodeJS

我正在使用 async/await 模型并在 NodeJS 中使用 Rascal lib 实现订阅的订阅消息。 我面临的问题是,我正在从订阅中获取内容,但无法将内容发送回被调用方方法。

module.exports = class RabbitmqClient {
    constructor(options) {
        this.options = options
    }

    async subscribe(broker,subscription) {
            try {
                logger.info(`Subscribing Messages for : ${subscription}`);
                const result = await broker.subscribe(subscription);
                await result.on('message', (message, content, ackOrNack) => {
                    //this logger is getting logged at very end of the flow.
                    logger.info(content)
                    return Promise.resolve(content);
                  }).on('error', (error) => {
                    var errMessage = "error occured during subscription process.."+error
                    logger.error('Error is: ', errMessage);
                    throw error;
                  });
                  // Execution jumps here and not waiting for above result.on to get process rather return from here and getting empty results in callee method
                  logger.debug("Subscription process ended succesfully..");
            } catch (err) {
                logger.error(`Error while subscribing the message ${JSON.stringify(err)}`);
                return Promise.reject(err);
            }
        }
}

所以如果我从另一个文件调用上面的方法作为

var rabbitmqObj = new rabbitmqClient()
var result = await rabbitmqObj.subscribe(connection, subscribe);
logger.info("result found is: "+JSON.stringify(result));

结果总是未定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM