簡體   English   中英

使用Java將警報推送到通知托盤應用程序

[英]Push alerts to notification tray app in Java

如何在不使用xmpp或其他繁重協議的情況下將服務器警報推送到java中的托盤應用程序?

你推薦一種方法來實現這個目標嗎?

我打算在配備Comet的服務器上編寫一個使用URLConnection的應用程序,但我懷疑這是否可行,因為客戶端需要調用JS而URLConnection不是瀏覽器..

推動而不是使用專有的客戶端 - 服務器方法的最佳方法是什么?

我在Mac上使用Growl從我的應用程序發送本地通知,但您也可以發送Growl遠程通知。 還有一個Windows版本 ,以及一個可用的Java庫 這是示例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"));

如果你有一個支持java的服務器和java客戶端,我會認真考慮使用Apache ActiveMQ。 JMS主題非常適用於這種推送(除非你有想要推銷Twitter的野心)。

當其他事情需要訪問這些通知時,查看Apache Camel可能會更好。 這允許接受通知並將其路由到不同的位置,即xmpp,email,http,刪除目錄中的文件,.... Camel附帶了一大堆現有的各種協議接口。 它有一些簡單的DSL可以快速重新配置路由並添加協議或其他過濾器,變壓器等......

這兩種產品都非常易於嵌入現有應用程序中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM