[英]How can I save some rules or config in google cloud and then call it to process a pubsub topic data in cloud functions?
I am working with google cloud functions.我正在使用谷歌云功能。 I am coming from a serverbased applications so I don't know much about the serverless world.
我来自基于服务器的应用程序,所以我对无服务器世界了解不多。
I have a scenario where i have two kinds in google datastore ie iot_kind and config_kind.我有一个场景,我在谷歌数据存储中有两种,即 iot_kind 和 config_kind。 One kind has config which is like a lookup table and other kind has normal payload values.
一种具有类似于查找表的配置,另一种具有正常的有效载荷值。
I am publishing the data from a IoT device into the pubsub topic and getting that data into the cloud functions.我正在将来自 IoT 设备的数据发布到 pubsub 主题并将该数据获取到云功能中。
eg IoT payload is例如物联网有效载荷是
{"id":"213213", 'price': 20, 'name':"some_name"}
then I am querying the config KIND and extracting some data from it like price multiplier然后我查询配置 KIND 并从中提取一些数据,如价格乘数
select *
from config_kind
where id = "213213" #lets say output is 2
Then I am multiplying the price*2 and saving it to IoT_kind eg value=40然后我乘以价格 * 2 并将其保存到 IoT_kind 例如 value=40
Now in this way I have to make a read every time I get a data into the cloud function which is i think quite expensive and also a bit processing.现在以这种方式,每次我将数据输入到云函数中时,我都必须进行读取,我认为这非常昂贵,而且处理起来也有点麻烦。
Is there any better way of doing it?有没有更好的方法来做到这一点? Like I save latest config somewhere and then whenever payload comes it sees the config and do the processing according to the config and then save it to a database?
就像我将最新的配置保存在某处,然后每当有效负载到来时,它都会看到配置并根据配置进行处理,然后将其保存到数据库中?
And can I do something like make a cloud function and store the latest value there and then call this cloud function from another cloud function to get the values out of it?我可以做一些事情,比如创建一个云函数并在那里存储最新的值,然后从另一个云函数调用这个云函数以从中获取值吗? would it be less expensive or expensive ?
它会更便宜还是更贵? Thanks a lot!
非常感谢!
Cloud Function is a serverless and stateless service. Cloud Function 是一种无服务器和无状态服务。 When an instance is created, it lived for a while and it has been stopped.
当一个实例被创建时,它存在了一段时间并且它已经停止了。 No disk are mount, all work in memory.
没有磁盘都挂载,都在内存中工作。 That means that you can't save any value in it persistently.
这意味着您不能持久地在其中保存任何值。
Anyway, you have 3 solutions to reduce the number of config read into datastore无论如何,您有 3 种解决方案来减少读入数据存储的配置数量
Is that make sense for you?这对你有意义吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.