Java消息系统 BBMS
fmms
13年前
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(); }
系统结构: