添加从Mysql服务器到Java应用程序的通知推送
您好,我已经使用 Netbeans 和 Mysql 在 Java SE 中设计了一个桌面应用程序。由于我所有的操作都是拉类型,所以我现在没有任何服务器编码。我需要一个推送通知功能。以前我有一个刷新通知的按钮,但现在我希望通知自动更新。
在不更改我现有代码的情况下添加此功能的最佳方法是什么?
任何帮助表示赞赏。 多谢
Hi I have designed a desktop application in Java SE with netbeans and Mysql.I do not have any server coding for now since all my operations were of pull type. I need a push notification functionality. Previously I had a button that refreshed the notification but now I want the notifications to be updated automatically.
What would be best way to add this functionality without changing much of my present code.
Any help appreciated.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实必须对架构进行大量更改才能使应用程序朝另一个方向发展。然而,我认为最好的方法是使用轻量级 JMS 提供程序。这样,您的客户端就可以编写 JMS API,这非常简单,而您的服务器可以使用 JMS,而且非常简单。它并不像管道其他选项那么费力。
更困难的部分是在应用程序中设置容器。这并不难,但 JMS 有很多配置选项。如果您以前没有使用过 JMS,则必须进行大量研究才能弄清楚点对点与主题、持久与非持久以及什么最适合您的应用程序。
但是,这为您提供了对应用程序中的消息传递的非常富有表现力的控制。您可以在不修改代码的情况下在轮询或直接连接、消息 1:1 或 1:many 之间进行交换。如果您需要向一个客户端发送消息与向所有客户端发送消息。您可以在客户端之间分段消息并创建组。您的消息可以是持久的或非持久的(在客户端关闭或服务器关闭后仍然存在)。可能性是无限的,但您必须做出很多架构决策。与使用 UDP 多播或反向 TCP 连接相比,您也不必处理网络拓扑和连接问题。
ActiveMQ 和 RabbitMQ 可以在 20 分钟内使用 spring 轻松嵌入到服务器中。他们还为其他平台提供挂钩。这听起来可能有点大材小用,但我过去曾尝试不使用 JMS,但当时我应该使用它,但后悔没有使用它。
You really will have to change a lot about your architecture to have your application go the other direction. However, I think the best approach is to use a light weight JMS provider. That way your client can code to the JMS API which is really pretty straight forward, and your server can use JMS and its really pretty easy. It's not nearly as much effort as plumbing other options in.
The harder part is setting up the container in your application. It's not tremendously hard, but JMS has lots of options for configuration. Figuring out the point to point vs topic, durable vs non-durable and what's right for your application is a lot of research you have to do if you haven't done JMS before.
But, what this affords you is a very expressive control over messaging in your application. You can under the covers without modifying your code swap between polling or direct connections, message 1:1 or 1:many. If you need to send a message to one client vs. sending a message to all clients. You can segment messages between clients and create groups. Your messages can be durable or non-durable (survive client shutdown or server shutdown). The possibilities are endless, but you have to make a lot of architectural decisions. You also don't have to handle network topology and connectivity issues as much than if you used UDP multicast or TCP connections in reverse.
ActiveMQ and RabbitMQ can be easily embedded within a server using spring in a matter of 20 minutes. They also provide hooks for other platforms. It might sound overkill, but I've tried to do without JMS in the past when I should've used it and regretted not using it.