[rabbitmq-discuss] building chat

Ram Muthiah ram.muthiah at yahoo.com
Thu Aug 27 03:05:06 BST 2009


Based on Ben and Alexis's discussion, I came up with the following logic. Let me know if you guys see any flaw in it. I use two exchanges; one for one-to-one chat and another for multi-user chat. Clients will use Java. I create one queue per user. Effectively, there will be two queues per chat. 



One-to-one chat:
 
When the user wants to send the message use SimpleProducer
class. For every 10 seconds, run SimpleConsumer class to see if there are any
messages in the queue.
 
SimpleProducer:
 
Publish the message in the window with the user’s name 
 
Connect to channel
 
Declare exchange named “direct”
Create queuename equivalent to the friend’s user name. 
Routing key is the same as the queuename.
 
Do channel.basicPublish to publish the message to the
friend.
 
If message is not acknowledged, show error as
“<friendname> is offline”.
 
SimpleConsumer:

Set noAck to false
 
Do channel.basicGet for the queuename “<username>”
 
If message is received successfully, do channel.basicAck to
acknowledge the receipt of the message.
 
Publish the incoming message with the friend’s name
 
 
Multi-user chat:
When the user wants to send the message use
SimpleProducerMulti class. For every 10 seconds, run SimpleConsumerMulti class
to see if there are any messages in the queue.
 
SimpleProducerMulti:
 
Connect to channel
 
Declare exchange named “multiuser”
Create queuename as “multiuserqueue”
Routing key is the same as the queuename..
 
Do channel.basicPublish to publish the message to
multiuserqueue.
 
If message is not acknowledged, show error as “server is
offline”.
 
SimpleConsumerMulti:

Set noAck to false
 
Use QueueingConsumer class 
 
Do channel.basicConsume for the queuename “<username>”
 
If message is received successfully, do channel.basicAck to
acknowledge the receipt of the message.
 
Publish the incoming message with the author’s name.

-- Thanks, Ram



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090826/716efb94/attachment.htm 


More information about the rabbitmq-discuss mailing list