从数据库获取通知

发布于 2025-01-08 04:47:01 字数 204 浏览 4 评论 0原文

我有数据库,例如 SQL,并从 3 方获取源到我的数据库中(每次更新)。例如,我需要在我的申请中收到通知:

select * form table Bonus > 50%

我应该使用Windows服务并检查所有数据库还是可以在sql中设置它并从SQL获取警报?我应该尽快收到通知,这样每隔 1 或 5 秒检查一次数据库就太难了。

I have database for example SQL and getting feeds from 3-party into my database (updating everytime it). I need get notification to my application when like examle:

select * form table Bonus > 50%

Shall I use windows services and check all database or can I set it in sql and get alert from SQL? I should get notification as soon as possible so to check database every 1 or 5 sec it will be too hard.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软甜啾 2025-01-15 04:47:01

这取决于您的数据库。几乎所有数据库都可以在数据更改时运行触发器,但触发器内部的代码通常是 SQL(不支持打开连接等)。

有些(例如 Oracle)允许触发器,并且还可以运行 Java 代码。在这里,您可以在数据库内构建一个解决方案。

但有一个缺点:如果信号无法发送怎么办?如果整个事务被回滚(这会损害其他相对不相关的服务)。

因此,通常的解决方案是编写代码,每隔一小时左右运行一次有问题的查询,然后在满足条件时发送信号。

如果查询是昂贵,那么您可以混合两者:仅在某些内容发生更改时运行查询(使用触发器)并将结果保存在表中(例如“$timestamp 发生了一些事情”)。在您的应用程序中,只需检查是否有更新自上次信号以来。

That depends on your database. Almost all databases can run triggers when data is changed but the code inside the trigger is usually SQL (which doesn't support opening connections and the like).

Some, like Oracle, allow triggers and they can run Java code as well. Here, you could build a solution inside the database.

But there is a drawback: What happens if the signal can't be sent? Should the whole transaction be rolled back (which would impair other, relatively unrelated services.

So the usual solution is to write code which runs the query in question every hour or so and then sends the signal when the condition is met.

If the query is expensive, then you can mix the two: Run the query only when something has changed (using the trigger) and save the result in a table (like "something happened at $timestamp). In your app, just check whether there was an update since the last signal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文