Не могу загрузить сообщение protobuf с protobuf.js - PullRequest
0 голосов
/ 26 октября 2019

Я пытаюсь использовать прото-сообщения с protobuf.js, кодировать их и отправлять в брокер сообщений RabbitMQ. У меня есть следующие подпапки внутри моего проекта:

- model
    - protos
        - transactions.proto
    - RabitMQ.js
- routes
    - rmq-api.js

Я добавил маршрут, который делает следующее (с помощью экспресс) в файле rmq-api.js:

const RabbitMQ = require('../model/RabbitMQ');

router.post('/api/transactions' ,function (req,res,next) {
    RabbitMQ.PublishTransactionsMessage(DummyMessage).then(() => {
      res.status(200).send({message: "OK :)"});
    }).catch((e) => {
        res.status(500).send({error:e.message});
    });
});

В файле RabitMQ.js у меня есть следующий код:

module.exports = {
    PublishTransactionsMessage: function(message) {
        return new Promise((resolve, reject) => {
            amqp.connect(RabbitMQConfig.url, function (error, connection) {
                if (error) {
                    console.error("Could not connect to the rabbit message broker on {0} - " +
                        "Check connection please and try again".format(RabbitMQConfig.url));
                    console.error("Error message - {0}".format(error));
                    reject(error)
                }
                connection.createChannel(function(error, channel) {
                    if (error) {
                        console.error("Could Create channel - {0}".format(error.message));
                        reject(error)
                    }
                    const queue = RabbitMQConfig.queue;
                    channel.assertQueue(queue, {
                        durable: true
                    });
                    // Convert Message to protobuff
                    protobuf.load("./protos/transactions.proto").then((err, root) => {
                        if (err) {
                            reject(err);
                        }
                        let ScraperMessageResult = root.lookupType("transactions.ScraperMessageResult");
                        const errMsg = ScraperMessageResult.verify(message);
                        if (errMsg)
                            reject(errMsg);
                        let buffer = ScraperMessageResult.encode(message).finish();
                        channel.sendToQueue(queue, buffer);
                        console.log(`Sent ${message} to queue: ${queue}`);
                        resolve()
                    }).catch((err) => {
                        reject(err);
                    });
                });
            });
        });
    },
};

В коде, показанном выше в строке: protobuf.load("./protos/transactions.proto").then((err, root) => { Я продолжаю ловить следующую ошибку: enter image description here

Внутри этого блока catch:

  }).catch((err) => {
      reject(err);
  });

Это кажется довольно простой проблемой, однако я не нашел ничего в этом онлайн, поэтому я мог бы упустить что-то очень простое здесь. PS Я пытался использовать __dirname + "/protos/transaction.proto" и все еще не мог заставить это работать. Пожалуйста, помогите мне разобраться.

...