Cloud Function 无法获取正确的 Pub/Sub 消息。

huangapple go评论58阅读模式
英文:

Cloud Function Can not Get Correct Pub/Sub MEssage

问题

我正在设置一个基于触发器的Google Cloud Platform (GCP) pub/sub云函数。云函数监听的主题是us-pubsub1。当我部署了云函数并使用测试面板发送消息时,如:

{"index":123,
"video_name":'test.mp4'}

在云函数中处理带有"index"和"video_name"键的消息时没有问题。但是,当我向us-pubsub1发送实际消息以触发云函数时,它总是因为无法在消息体中找到"index"而失败。当在云函数中读取pub/sub消息时,它返回给我消息如下:

{'@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage',
'attributes': None, 'data':
'eyJzZXNzaW9uX2lkIjogImUzYjM0MTJiLWQxNWUtNDM5My05YjEy-5Z2-7IzcTO4L3QuNW'
}

我已经确认消息正确到达us-pubsub1,只是无法在云函数中处理。是否有什么我错过的东西,以获取真正的云函数消息体?

英文:

I am setting up a pub/sub trigger-based cloud function in GCP, the topic the cloud function listen to is us-pubsub1. When I deployed the cloud function and used the testing panel to send messages like:

{"index":123,
"video_name":'test.mp4'}

in cloud function to processing the message with key index and video_name, it has no issue. But when I sent a real message to us-pubsub1 to trigger the cloud function, it always failed for not able to find the 'index' in the message body. and when reading the pub/sub message in cloud function, it return me messages like:

> {'@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage',
> 'attributes': None, 'data':
> 'eyJzZXNzaW9uX2lkIjogImUzYjM0MTJiLWQxNWUtNDM5My05YjEyLWI3ZGY1ZGE4MTQ0NCIsICJzZXNzaW9uX25hbWUiOiAiU0VTU0lPTl9DMjIjMwMTI1VDIwMTI1NCIsICJzaXRlX25hbWUiOiAiVkEgTUVESUNBTCBDRU5URVIgLSBQQUxPIEFMVE8gLSc3RlY3RvbXkiLCAiaHViX3NlcmlhbF9udW1iZXIiOiAiQzIyNC0wMDIwNSIsICJjYXN0X2FwcF92ZXJzaW9uIjogIjEyLjAuMzIuNyIsICJkdl9zeXN0ZW0iOiAiVUFUU0syMDA3IiwgImludGVybmFsX2tleSI6ICJtNjQzY2U1NS0zNjNiLQ=='}

I checked that the message arrive in us-pubsub1 correctly and just failed to process in cloud function.

Is there any thing I have missed for fetching the message body for real cloud function?

答案1

得分: 1

这是正常的。您有一个发布订阅消息封装,您的内容以 base64 编码方式在数据字段中。这里有文档详细信息

顺便说一下,这是您示例的实际内容(部分内容已截断,可能没有分享整个内容)。

英文:

It's normal. You have a pubsub message enveloppe and your content is base64 encoded in the data field. Here the documentation details


FWIW, here the real content of your sample

{"session_id": "e3b3412b-d15e-4393-9b12-b7df5da81444", "session_name": "SESSION_C22#3#UC##SB"'6FUR#%dTD44TDU"Dstectomy", "hub_serial_number": "C224-00205", "cast_app_version": "12.0.32.7", "dv_system": "UATSK2007", "internal_key": "m643ce55-363b-

it is truncated, you might not share the whole content Cloud Function 无法获取正确的 Pub/Sub 消息。

huangapple
  • 本文由 发表于 2023年2月8日 09:09:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75380484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定