gcp-在数据库插入时触发云功能? [英] gcp - Trigger Cloud Function on database insert?

查看:57
本文介绍了gcp-在数据库插入时触发云功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定如何搜索;我正在寻找一种在Cloud SQL的数据库中插入新行时触发Cloud Function的方法.搜索"Google云功能事件"(或触发器")会显示Firebase结果,这不是我想要的.

Not sure how to search this; I'm looking for a way to trigger a Cloud Function whenever a new row is inserted into a database in Cloud SQL. The search for "google cloud function events" (or "triggers") turn up Firebase results, which is not what I want.

有一系列云功能可以接收数据并根据客户的需求对其进行转换;最后,经过一些操作,该数据最终存储在一个表中.有没有可以听的事件以便可以访问新插入的行?如果没有,我可能最终会使用Cloud Scheduler并定期浏览数据库.但是,从长远来看,这种解决方案似乎并不可行.

There are a series of Cloud Functions that receive data and transform it according to the clients' needs; in the end, after some manipulation, that data ends up in a table. Is there an event I can listen to so I can access the newly inserted rows? If not, I might end up using the Cloud Scheduler and peek regularly into the DB. However, this solution doesn't seem viable for long-term.

我将不胜感激.

推荐答案

当前没有官方的Cloud Function事件,该事件可以在Cloud SQL数据库的更改时触发.您可以在事件和触发器文档中检查可用事件

Currently there is no official Cloud Function event which could be triggered on changes to a Cloud SQL database. You can check the available events in the Events and Triggers documentation.

您仍然可以使用Cloud Pub/Sub做类似的事情,并且可以通过2种方式完成:

You could still do something like it with Cloud Pub/Sub, and it could be done in 2 ways:

1-首先是通过

1 - The first would be to enable and export logs from the Cloud SQL instance to a Pub/Sub topic by creating a sink on Stackdriver, and have the Cloud Function listen to that topic.

尽管此方法不需要您更改向DB插入数据的方式,但是由于所有查询都将记录在Stackdriver上,因此它可能会公开太多信息.这也意味着您将无法完全控制将什么信息传递给该函数,因为该消息将是日志条目的内容.

Although this method does not require you to change the way you are inserting data to the DB, it might expose too much information, as all queries will be logged on Stackdriver. It also means you would not have full control of what information is passed to the function, as the message would be the contents of the log entry.

2-理想的解决方案是创建Pub/Sub主题,然后在将新数据插入数据库时​​发布到该主题.这样,您可以更好地控制发送给主题的信息.您可以在 Cloud Pub/Sub 文档.

2 - The ideal solution would be to create the Pub/Sub topic and publish to it when you insert new data to the database. This way you have more control over the information sent to the topic. You can find more information about how to set up a new topic in the Cloud Pub/Sub documentation.

这篇关于gcp-在数据库插入时触发云功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆