Websocket 服务器检测数据库中的数据变化 [英] Websocket server detect data change in database

查看:27
本文介绍了Websocket 服务器检测数据库中的数据变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地主机中使用 Java 创建了一个 websocket 服务器,并创建了与 websocket 服务器连接的 android 应用程序,并且我在另一个虚拟主机中有数据库 websocket 服务器如何检测数据库中的任何更新?

I create a websocket server with Java in my localhost and i create android app connect with the websocket server and i have database in another web hosting how can the websocket server detect any update in the database ?

推荐答案

根据 stack overflow 上的研究链接,MS SQL 服务器不会触发任何可以通过 Java 应用程序观察到的通知 如此处评论

According the fellowing links on stack overflow MS SQL server doesn't fire any notification that can be observed via Java applications as here in comments

那我们能做什么?创建我们自己的听众!

我们有两个假设

  1. 如果您通过应用程序对数据库进行操作(插入、更新...):因此您可以在您的 Java 服务器上创建一个 webservice应用程序使用(即调用)这个网络服务,当有新的数据更新时,网络服务会通知web-socket实例

  1. If you make operations(insert,update...) on database via an applications: hence you can create a webservice on your Java server and the application consumes(ie:call) this web service when a new data is updated, and the web service will notify the web-socket instances

如果直接从 DBMS 访问数据库,那么 MS SQL Server 触发器只能调用 CLR 如上所述here 所以你需要使用 创建一个 TimerEJB 观察数据库,但这将是最糟糕的解决方案

If the database is accessed directly from the DBMS, so MS SQL Server triggers can only invoke only CLRas mentioned here so you need to create a Timer using EJB that observes the database but this will be the worst solution

我希望这是有用的(:

这篇关于Websocket 服务器检测数据库中的数据变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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