Java消息系統 BBMS
BBMS(Bus Based Message Service)是一個采用Java開發的消息系統。BBMS應用程序能夠異步發送消息到其它任意客戶端發送并接收客戶端的消息。BBMS提供了易于使用 的API,并擁有高性能和靈活性。它類似于JMS(Java Message Service) 但現在還不支持pub/sub模式。當前只支持P2P。
public static void main(String[] args) throws RemoteException{
/*
* create a notifiable entry, declare that it's care of
* TIMEOUT, CLOSE, and READY event.
*/
Configuration config = new RMIServerConfiguration(null, 0);
CommonNotifiableEntry entry1 =
new CommonNotifiableEntry(config, "client1",
MessageTypes.MESSAGE_TIMEOUT |
MessageTypes.MESSAGE_CLOSE |
MessageTypes.MESSAGE_READY);
/*
* create another notifiable entry, declare that it's care of
* OPEN, CLOSE, and TIMEOUT event.
*/
CommonNotifiableEntry entry2 =
new CommonNotifiableEntry(config, "client2",
MessageTypes.MESSAGE_OPEN |
MessageTypes.MESSAGE_CLOSE |
MessageTypes.MESSAGE_TIMEOUT);
// register them to the remote Message BUS to listener events
entry1.register();
entry2.register();
// new a message, of type MESSAGE_OPEN.
Message msg = new CommonMessage(
entry1.getId(),
entry2.getId(),
MessageTypes.MESSAGE_OPEN,
"busying now");
// deliver it to entry2, which is from entry1
entry1.post(msg);
// create a message, of type MESSAGE_CLICKED, the entry2
// does not handle this type, it'll not be deliver to entry2
Message msgCannotBeReceived = new CommonMessage(
entry1.getId(),
entry2.getId(),
MessageTypes.MESSAGE_CLICKED,
"cliked evnet");
entry1.post(msgCannotBeReceived);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// re use the message object to send another message entry
msg.setSource(entry2.getId());
msg.setTarget(entry1.getId());
msg.setType(MessageTypes.MESSAGE_READY);
msg.setBody("okay now");
entry2.post(msg);
// unregister self when all works are done or
// don't want to listen any more
entry1.unregister();
entry2.unregister();
}
系統結構:

本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!