简体   繁体   中英

Clustered chat implementation based on Queue

I'm working on chat implementation. The idea is very simple there is map with where keys are userNames and values are queue of messages which should be delivered to user

This map is represented by ConcurrentHashMap<String, <ConcurrentLinkedQueue<Message>>>

When new messaged for user arrived it is written to this map, and every user fetch their messages from queue using simple http pooling. This approach works fine.

Now i need implement similar functionality in cluster. For cache replication i use jboss cache. Right now cache replication works in synchronous fashion. This mean that write on local node to cache would not occur before write on others nodes.

Basically cache interface looks similar to map with put and get methods.

Right now i would replicate the whole queue. When new messaged arrived i get queue from map, add new message in queue and “put” (rewrite) new queue on all nodes.

When request comes from the user to fetch new messages to clone current queue, make queue associated with with this user empty on all nodes and deliver messages to user from cloned queue.

I feel there are a lot of cases, when something might go wrong. For example i put message on queue on node A, replication of queue started and right now on another node B user fetch messages from queue making queue empty. And later replication of queue from node A finished and node B got already delivered messages again. User receive same messages twice

What is the common approach to implement this mesage routine in cluster ?

In short, messaging. You can roll your own based on JMS, or use an Enterprise Service Bus .

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