Firebase功能不响应发布/订阅消息

时间:2017-03-23 07:55:38

标签: node.js firebase google-cloud-pubsub google-cloud-functions

我觉得我可能会遗漏一些简单的内容,但我无法让Firebase的Cloud功能响应Pub / Sub发布的消息。当我使用云部署并选择Admin SDK for Node.js时,它工作正常,但Auth很棘手;它适用于第一次写入,然后无法进行身份验证。

随着Cloudbase for Firebase的发布,我决定再试一次。我的功能代码如下:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

function pushOrderToFirebase(completedOrder) {

  admin.initializeApp(functions.config().firebase);

  //setters and getters for the message that will be pushed to firebase

  admin.database().ref('/orders').push({
    name: curDriverName,
    recipient: recipient,
    address: address,
    details: details,
    isDelivered: isDelivered,
    failureReason: failureReason,
    time: formattedTime
  }).then(snapshot => {
    console.log(snapshot);
  });
}
exports.firebasePusherAlpha = functions.pubsub.topic('test-topic').onPublish(event => {
  const pubSubMessage = event.data;

  let parsedMessage = null;
  try {
    parsedMessage = pubSubMessage.json;
    console.log(parsedMessage);
  } catch (e) {
    console.error('PubSub message was not JSON', e);
  }
  pushOrderToFirebase(parsedMessage);
  callback();
});

不幸的是,当我发布pubsub消息时,它不会被调用。

0 个答案:

没有答案