简体   繁体   中英

How to implement message Queue one per client?

I currently implementing a peer to peer messaging application in java. Currently I am bit stuck with one issue. In my application I want a message queue that will be residing in each peer and Other peer which wants to communication other peer actually goes ahead and write there message in other peers MQ (message Queue).

For Eg. A and B are two different peers/Nodes in a network.

Now A wants to sent a message to B, then it goes ahead and writes its message to B's Queue. And B will keep on pulling messages from it's own MQ.

I don't know what Java library to use which could easily allow me to implement this.

I have searched a lot about this and never found a proper solution for this.

Can any one suggest me a good way to implement this.

Phisically sending messages from A to B is simple enough, just open the sockets or use a non blocking networking library such as Netty or Apache Mina . Both provide several examples of implementing network communications on top of their stacks.

You'll probably need to decide how the network topology is, if there are just 2-3-4 peers connected, you can simply have each peer have an open socket for each of the other peers.

If there are expected to be many peers, having a socket for each would be difficult or even impossible, and a different topology is necessary:

  1. Each peer has knowledge of just a few of its neighbours, the other peers are reachable by hopping from peer to peer using some routing logic.
  2. Another solution is to have a centralized node where all peers checkin (this is how Skype or most other IM networks work).

I think I could use RMI for this Purpose. In my case each peer will act as a server and run rmiregistry. And my interface file will contain apis to populate the Message Queue. other peer will use RMI to call API's to update the Queue. Indirectly my other peers will update the Message Queue on the peer which it want to communicate.

I don't know whether this is a correct way to implement it, All suggestions are still welcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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