简体   繁体   English

使用Java将警报推送到通知托盘应用程序

[英]Push alerts to notification tray app in Java

how do I push server alerts to tray apps in java without using xmpp or other heavy protocols? 如何在不使用xmpp或其他繁重协议的情况下将服务器警报推送到java中的托盘应用程序?

Do you recommend a way to accomplish this? 你推荐一种方法来实现这个目标吗?

I was planning to write an app which uses URLConnection on a server equipped with Comet but I doubt if that would work as the client requires a JS to be invoked and URLConnection is not a browser.. 我打算在配备Comet的服务器上编写一个使用URLConnection的应用程序,但我怀疑这是否可行,因为客户端需要调用JS而URLConnection不是浏览器..

What is the best way to push instead of using a proprietary client-server approach? 推动而不是使用专有的客户端 - 服务器方法的最佳方法是什么?

I use Growl on my Mac for local notifications from my apps, but you can also send Growl remote notifications. 我在Mac上使用Growl从我的应用程序发送本地通知,但您也可以发送Growl远程通知。 There's also a Windows version , as well as a Java library available. 还有一个Windows版本 ,以及一个可用的Java库 Here's the example Java code (needs Java 6): 这是示例Java代码(需要Java 6):

// give your application a name and icon (optionally)
Application serverApp = new Application("Server App");

// create reusable notification types, their names are used in the Growl settings
NotificationType start = new NotificationType("ServerStart");
NotificationType shutdown = new NotificationType("ServerShutdown");
NotificationType[] notificationTypes = new NotificationType[] {start, shutdown};

// connect to Growl on the given host
GrowlConnector growl = new GrowlConnector("localhost");

// now register the application in growl
growl.register(serverApp, notificationTypes);

// finally send the notification
growl.notify(new Notification(serverApp, start, "Server is starting", "Good luck"));

If you have a java capable server and java clients, I would seriously consider using Apache ActiveMQ. 如果你有一个支持java的服务器和java客户端,我会认真考虑使用Apache ActiveMQ。 A JMS topic works really well for this kind of push things (unless you have ambitions to dethrone twitter). JMS主题非常适用于这种推送(除非你有想要推销Twitter的野心)。

When other things need to get access to these notifications, it might be good to look at Apache Camel. 当其他事情需要访问这些通知时,查看Apache Camel可能会更好。 This allows the notifications to be accepted and routed to different locations, ie xmpp, email, http, dropping files in a directory,.... Camel comes with a whole bunch of existing interface to various protocols. 这允许接受通知并将其路由到不同的位置,即xmpp,email,http,删除目录中的文件,.... Camel附带了一大堆现有的各种协议接口。 It has some simple DSL's to quickly reconfigure routings and add protocols or other filter, transformers, etc... 它有一些简单的DSL可以快速重新配置路由并添加协议或其他过滤器,变压器等......

Both products are extremely simple to embed in an existing application. 这两种产品都非常易于嵌入现有应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM