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 PubSub不会在每条新消息中触发函数_Google Cloud Platform_Google Cloud Pubsub - Fatal编程技术网

Google cloud platform Google PubSub不会在每条新消息中触发函数

Google cloud platform Google PubSub不会在每条新消息中触发函数,google-cloud-platform,google-cloud-pubsub,Google Cloud Platform,Google Cloud Pubsub,我有一个GooglePubSub流,每天都会添加一组地址。我希望这些地址中的每一个都由触发的谷歌云功能处理。然而,我看到的是,每个地址只被处理一次,即使每天有一条新消息添加到流中 我的问题是,如果每天向流中添加相同的值,它会作为新消息处理吗?或者它将被视为重复消息 这就是我看到的情况。每天都会触发位置云功能,并将每个位置发布到位置主题。大多数情况下,这些信息与前一天的信息相同。它们唯一改变的时间是某个位置关闭或添加了新位置。然而,我看到的是,许多位置消息从未被位置度量云函数拾取 函数的流程如下所

我有一个GooglePubSub流,每天都会添加一组地址。我希望这些地址中的每一个都由触发的谷歌云功能处理。然而,我看到的是,每个地址只被处理一次,即使每天有一条新消息添加到流中

我的问题是,如果每天向流中添加相同的值,它会作为新消息处理吗?或者它将被视为重复消息

这就是我看到的情况。每天都会触发
位置
云功能,并将每个位置发布到
位置
主题。大多数情况下,这些信息与前一天的信息相同。它们唯一改变的时间是某个位置关闭或添加了新位置。然而,我看到的是,许多
位置
消息从未被
位置度量
云函数拾取

函数的流程如下所示:

主题每天在2a触发(称为
位置\u触发器
)>触发器
位置
云功能>发送到
位置
主题>触发器
位置度量
云功能>发送到
位置度量
主题

对于
位置
云功能,它会被触发并正确返回所有地址,然后将它们发送到
位置
主题。我不会把整个函数放在这里,因为它没有问题。对于它检索到的每个位置,日志中都有一条“发布成功”消息。下面是将位置详细信息发送到主题的部分

        project_id = "project_id"
        topic_name = "locations"
        topic_id = "projects/project_id/topics/locations"

        publisher = pubsub_v1.PublisherClient()
        topic_path = publisher.topic_path(project_id, topic_name)

        try:
            publisher.publish(topic_path, data=location_details.encode('utf-8'))
            print("publish successful: ", location)
        except Exception as exc:
            print(exc)
发送的
位置
有效负载示例如下:
{“id”:“accounts/123456/locations/123456”,“name”:“Business 123 Main st10010”}

location\u metrics
函数如下所示:

def get_metrics(loc):
    request_body = {
      "locationNames": [ loc['id'] ],
      "basicRequest" : {
              "metricRequests": [
                 {
                   "metric": 'ALL',
                   "options": ['AGGREGATED_DAILY']
                 }
              ],
              "timeRange": {
                   "startTime": start_time_range,
                   "endTime": end_time_range,
              },
        }
    }

    request_url = <request url> 
    report_insights_response = http.request(request_url, "POST", body=json.dumps(request_body))

    report_insights_response = report_insights_response[1]
    report_insights_response = report_insights_response.decode().replace('\\n','')
    report_insights_json = json.loads(report_insights_response)

            <bunch of logic to parse the right metrics, am not including because this runs in a separate manual script without issue>

            my_data = json.dumps(my_data)

            project_id = "project_id"
            topic_name = "location-metrics"
            topic_id = "projects/project_id/topics/location-metrics"

            publisher = pubsub_v1.PublisherClient()
            topic_path = publisher.topic_path(project_id, topic_name)

            print("publisher: ", publisher)
            print("topic_path: ", topic_path)
            try:
                publisher.publish(topic_path, data=gmb_data.encode('utf-8'))
                print("publish successful: ", loc['name'])
            except Exception as exc:
                print("topic publish failed: ", exc)

def retrieve_location(event, context):
    auth_flow()
    message_obj = event.data
    message_dcde = message_obj.decode('utf-8')
    message_json = json.loads(message_dcde)

    get_metrics(message_json) 
def get_度量(loc):
请求正文={
“位置名称”:[loc['id']],
“基本任务”:{
“metricRequests”:[
{
“公制”:“全部”,
“选项”:[“每日汇总”]
}
],
“时间范围”:{
“开始时间”:开始时间范围,
“结束时间”:结束时间范围,
},
}
}
请求\u url=
report\u insights\u response=http.request(请求\u url,“POST”,body=json.dumps(请求\u body))
报告洞察响应=报告洞察响应[1]
report\u insights\u response=report\u insights\u response.decode().替换('\\n','')
report\u insights\u json=json.load(report\u insights\u响应)
my_data=json.dumps(my_data)
project\u id=“project\u id”
topic_name=“位置度量”
topic\u id=“项目/项目\u id/主题/位置度量”
publisher=pubsub_v1.publisher客户端()
主题路径=发布者。主题路径(项目id,主题名称)
打印(“出版商:”,出版商)
打印(“主题路径:”,主题路径)
尝试:
publisher.publish(主题路径,数据=gmb\u数据.encode('utf-8'))
打印(“发布成功:”,loc['name'])
除作为exc的例外情况外:
打印(“主题发布失败:”,exc)
def检索位置(事件、上下文):
验证流()
message_obj=event.data
消息\u dcde=消息\u对象解码('utf-8')
message_json=json.load(message_dcde)
获取度量(消息json)

Pubsub将消息作为消息处理。没有重复删除或其他奇怪的东西根据日期。你的问题可能来自另一个原因。可能在您的代码中。或者您用来检查消息处理的方法是错误的。文档页面中关于消息处理的解释是否回答了您的问题?@Nick_Kh不是这样的。第一次之后,不会处理新消息。这就好像在地址被发送后,同一地址就再也不会被处理一样。@analyticsPierce,你能解释一下如何触发特定的云功能吗?@Nick_Kh我添加了一些细节来帮助澄清。