Google cloud platform 在模拟器中以编程方式调用gcloud后台函数

Google cloud platform 在模拟器中以编程方式调用gcloud后台函数,google-cloud-platform,google-cloud-functions,google-cloud-pubsub,serverless,Google Cloud Platform,Google Cloud Functions,Google Cloud Pubsub,Serverless,我在emulator中部署了一个gcloud后台函数(pubsub) 它正在从命令行成功调用 functions call helloPubSub --data='{"message":"Hello World"}' 如何从本地服务器代码调用gcloud本地函数 === 下面是我在服务器端发布到主题的代码 pubsub .topic(topicName) .publisher() .publish(dataBuffer) .then(results => { co

我在emulator中部署了一个gcloud后台函数(pubsub)

它正在从命令行成功调用

functions call helloPubSub --data='{"message":"Hello World"}'
如何从本地服务器代码调用gcloud本地函数

===

下面是我在服务器端发布到主题的代码

pubsub
  .topic(topicName)
  .publisher()
  .publish(dataBuffer)
  .then(results => {
    const messageId = results[0];
    console.log(`Message ${messageId} published.`);
    res.status(200)
    res.send({hello:'world'})

  })
  .catch(err => {
    console.error('ERROR:', err);
    res.status(200)
    res.send({err:err})
  });    
我收到以下错误消息

{"err":{"code":7,"metadata":{"_internal_repr":{}},"note":"Exception occurred in retry method that was not classified as transient"}}
在报告中指出:

注意:这些服务不会调用Emulator中部署的具有非HTTP触发器(如云存储或云发布/订阅)的函数。Emulator仅用于开发环境,因此需要手动调用这些函数才能调用它们

因此,如果您使用Cloud Pub/Sub触发器在本地部署了一个函数,那么调用它的唯一方法就是使用命令行命令:

functions call [your-function]