Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何从云函数中提取发布/订阅消息?_Google Cloud Platform_Google Cloud Functions_Google Cloud Pubsub - Fatal编程技术网

Google cloud platform 如何从云函数中提取发布/订阅消息?

Google cloud platform 如何从云函数中提取发布/订阅消息?,google-cloud-platform,google-cloud-functions,google-cloud-pubsub,Google Cloud Platform,Google Cloud Functions,Google Cloud Pubsub,我想使用云函数从发布/订阅中提取消息。因此,我设置了主题的提取订阅。然后我每小时用云调度器触发一次云功能 如果我需要使用pull,是否有更好的方法 我从文档中复制了一个示例,但它抛出了一个错误 TypeError: match error: could not instantiate a path template from projects/projectname/subscriptions/projects/projectname/subscriptions/test at PathT

我想使用云函数从发布/订阅中提取消息。因此,我设置了主题的提取订阅。然后我每小时用云调度器触发一次云功能

  • 如果我需要使用pull,是否有更好的方法
  • 我从文档中复制了一个示例,但它抛出了一个错误

     TypeError: match error: could not instantiate a path template from 
     projects/projectname/subscriptions/projects/projectname/subscriptions/test at PathTemplate.match 
     (/srv/node_modules/google-gax/build/src/pathTemplate.js:82:19) at PathTemplate.render 
     (/srv/node_modules/google-gax/build/src/pathTemplate.js:118:14) at SubscriberClient.subscriptionPath 
     (/srv/node_modules/@google-cloud/pubsub/build/src/v1/subscriber_client.js:1838:57) at 
     exports.helloPubSub (/srv/index.js:22:45) at /worker/worker.js:825:24 at <anonymous> at 
     process._tickDomainCallback (internal/process/next_tick.js:229:7)
    

    谢谢

    这一行出现错误消息:

    const formattedSubscription = subClient.subscriptionPath(projectId, subscriptionName);
    
    因为您的“我的订阅的名称”是
    projects/your project/subscriptions/subname
    ,而不是
    subname

    const subscriptionName = 'name_of_my_subscription'; 
    
    这就是为什么您会得到双重名称
    项目/projectname/subscriptions/

     could not instantiate a path template from 
    
    projects/projectname/subscriptions/projects/projectname/subscriptions/test
    

    我认为您可以使用CloudFunctions让发布/子主题发布直接触发该函数。。。看见这有可能吗?您是否希望成批处理邮件?我有多个项目需要使用我的项目中的邮件。以前,我在其他项目中将消息推送到他们的主题。我更喜欢发布到项目中某个主题的解决方案。并让其他项目获取信息。这将减少依赖性,我不必发布和维护其他项目的10个不同主题。我的理解是,GCP发布/订阅中的耦合是发布者、主题和订阅的概念。主题不包含消息。。。它是消息发布到的目标。每个希望接收消息的应用程序都会创建自己的订阅。这似乎告诉我,您的每个不同应用程序都可以有自己的订阅。这意味着订阅应用程序控制他们看到的消息。
     could not instantiate a path template from 
    
    projects/projectname/subscriptions/projects/projectname/subscriptions/test