Postgresql - 检测更改并调用 webservice

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15505286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:50:32  来源:igfitidea点击:

Postgresql - detect changes and call webservice

postgresql

提问by diego10

I have a PostgreSQL database. What I want to do is, detect any changes (insert, update) that happen in the database and then call a webservice. How could I do this?

我有一个 PostgreSQL 数据库。我想要做的是,检测数据库中发生的任何更改(插入、更新),然后调用 Web 服务。我怎么能这样做?

Thanks in advance for any help.

在此先感谢您的帮助。

回答by Henning

You should be able to use triggers and the listen/notify functionality in PostgreSQLto achieve something like this:

您应该能够使用PostgreSQL 中的触发器和侦听/通知功能来实现以下目标:

  1. A set of insert/update/delete triggerscreate a notification event whenever anything changes in your table, using the created/changed/deleted ID as the payload.

  2. A background process checks for notifications periodically (here's an example using Java/JDBC), and then loads the changed record from the database to do the web service call.

  1. 一组插入/更新/删除触发器会在表中发生任何变化时创建一个通知事件,使用创建/更改/删除的 ID 作为有效负载。

  2. 后台进程会定期检查通知(这里是使用 Java/JDBC 的示例),然后从数据库加载更改的记录以执行 Web 服务调用。

This is not in any way a real-time push-type system, but you have to poll the database for notification events to trigger the webservice call. It will do the trick, though.

这在任何方面都不是实时推送型系统,但您必须轮询数据库以获取通知事件以触发 Web 服务调用。不过,它会奏效。