从数据库获取事件 [英] Getting events from a database

查看:173
本文介绍了从数据库获取事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太熟悉数据库以及他们在CRUD操作之外提供的内容。

I am not very familiar with databases and what they offer outside of the CRUD operations.

我的研究使我得到触发器。基本上它看起来像触发器提供这种类型的功能:

My research has led me to triggers. Basically it looks like triggers offer this type of functionality:


(来自维基百科

通常有三个触发事件会导致触发器触发:

There are typically three triggering events that cause triggers to "fire":


  • INSERT事件(正在将新记录插入到数据库中)。

  • UPDATE事件


(已删除)。
<

我的问题是:有一些方法,当一个记录被更新/删除/插入使用某种触发语义时,我可以通过数据库中的Java通知(最好包括更改的数据)。

My question is: is there some way I can be notified in Java (preferably including the data that changed) by the database when a record is Updated/Deleted/Inserted using some sort of trigger semantics?

这个问题的一些替代解决方案是什么?我如何监听数据库事件?

What might be some alternate solutions to this problem? How can I listen to database events?

我想这样做的主要原因是这样的情况

我有5个客户端应用程序都在不同的进程/不同的PC存在。它们都共享一个公共数据库(在这种情况下是Postgres)。

I have 5 client applications all in different processes/existing across different PCs. They all share a common database (Postgres in this case).

假设一个客户端更改DB中所有5个客户端都感兴趣的记录。我试图想办法为客户端通知的变化(最好是与受影响的数据附加),而不是他们查询数据在一定的间隔。

Lets say one client changes a record in the DB that all 5 of the clients are "interested" in. I am trying to think of ways for the clients to be "notified" of the change (preferably with the affected data attached) instead of them querying for the data at some interval.

推荐答案

使用Oracle,您可以在表上设置一个触发器,然后让触发器发送JMS消息。 Oracle有两个不同的JMS实现。然后,您可以有一个进程,将使用JDBC驱动程序侦听消息。我使用这种方法将更改推送到我的应用程序与轮询。
如果您使用的是Java数据库(H2),则还有其他选项。在我当前的应用程序(SIEM)中,我有H2中的触发器,使用JMX发布更改事件。

Using Oracle you can setup a Trigger on a table and then have the trigger send a JMS message. Oracle has two different JMS implementations. You can then have a process that will 'listen' for the message using the JDBC Driver. I have used this method to push changes out to my application vs. polling. If you are using a Java database (H2) you have additional options. In my current application (SIEM) I have triggers in H2 that publish change events using JMX.

这篇关于从数据库获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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