开发者

Clustered chat implementation based on Queue

开发者 https://www.devze.com 2023-04-10 18:49 出处:网络
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

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 byConcurrentHashMap<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开发者_JAVA百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号