<div dir="ltr"><div class="gmail_quote"><div class="im">On Fri, Aug 7, 2009 at 12:52 PM, Alexis Richardson <span dir="ltr">&lt;<a href="mailto:alexis.richardson@gmail.com" target="_blank">alexis.richardson@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Ben,<br>
<br>
Further to your email exchanges with Paul...<br>
<div><br>
On Thu, Aug 6, 2009 at 3:32 PM, Ben Browitt&lt;<a href="mailto:ben.browitt@gmail.com" target="_blank">ben.browitt@gmail.com</a>&gt; wrote:<br>
</div><div>&gt; Hi,<br>
&gt;<br>
&gt; I&#39;m trying to understand how AMQP and RabbitMQ works by building a simple<br>
&gt; chat.<br>
<br>
</div>Cool :-)<br>
<div><br>
<br>
&gt; From reading the AMQP specs I get the impression that it&#39;s best usage is<br>
&gt; when someone publish content to an exchange<br>
&gt; and someone else bind his queue to this exchange to get updates. This model<br>
&gt; works very well for publish-subscribe<br>
&gt; and to finance systems but chat could be different.<br>
<br>
</div>I think chat is a very natural application of AMQP. �The benefit of<br>
using XMPP would be to integrate with existing chat infra in a<br>
standard way, but that does not prevent you from using an AMQP based<br>
implementation underneath.<br>
<br>
Do you want to do MUC or IM?</blockquote></div><div><br>I&#39;m not actually building it.<br>I keep hearing about AMQP and RabbitMQ so I read the spec and the server docs.<br>I couldn&#39;t find use cases on the web so I thought I&#39;ll try to fit the protocol to a fun application.<br>

�<br></div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
In fact, you can use a single approach to both.<br>
<br>
One approach is to have one queue per consumer &#39;chat window&#39; and one<br>
exchange per &#39;chat room&#39;. �The queue is bound to the exchange when the<br>
user is in the chatroom. �Then, IM is a special case of MUC - it is a<br>
chatroom with two participants.<br>
<br>
Another approach would be to have one queue per consumer, and have<br>
that queue bound to the exchange(s) N times, where N is the number of<br>
chatrooms (or IMs) which the consumer is currently in. �In this<br>
approach, you will need to identify which message came from which<br>
room, before you show the messages to the user. �That&#39;s easy but it&#39;s<br>
extra work and data to carry around.<br>
</blockquote></div><div><br>When a client sends a message to another client he usually doesn&#39;t create a chatroom for two,<br>
he just sends the message and the server routes it. With your suggestion the server will create<br>
the room if it doesn&#39;t exists when it needs to route a message.<br>
When all the users leaves a MUC room if it is not persistent the server destroys it.<br>
What will be the case with a chatroom with two participants?<br>
Maybe the server will destroy it when both users are offline?<br>Is there a way to destroy an exchange if it is not active for several minutes to save memory?<br>Can you use a standard XMPP client with this setup?<br>�<br>

</div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Let me know if you want more detail on either of the above, eg which<br>
exchange type to use.</blockquote></div><div><br>I thought of a non durable exchange. One exchange per chatroom and one queue per user.<br><br>�<br></div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
<div><br>
<br>
&gt; I read the xmpp gateway<br>
&gt; docs and have some questions.<br>
&gt;<br>
&gt; In a chat we want to be able to get presence from users on our friend-list,<br>
&gt; send them messages<br>
&gt; and send subscription request and messages to users not yet on our<br>
&gt; friend-list.<br>
<br>
</div>Do you only want to enable chat when both users are online and have a<br>
&#39;friend&#39; relationship?<br>
<div><br>
<br>
&gt; One possibility is that each user will have an exchange and a queue with<br>
&gt; binding to his own exchange.<br>
&gt; When user1 wants to send a message to user2 he send it directly to the<br>
&gt; exchange of user2.<br>
&gt; There is a problem with presence updates. If user1 changes his presence,<br>
&gt; he&#39;ll have to�sends the update<br>
&gt; to the exchange of all the users�on his friend-list. With this design we<br>
&gt; move the logic to the client rather then use the AMQP features.<br>
<br>
</div>One approach to presence is to broadcast changes using the pubsub<br>
system. �Changes could include:<br>
<br>
* User goes online / offline<br>
* User changes their &#39;status message&#39;<br>
</blockquote><div>�</div></div><div>All I know is that there are queues exchanges and bindings.<br>What do you mean by the pubsub system? <br><br></div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
<br>
&gt; Another option is that when a user logs in he&#39;ll create a binding to the<br>
&gt; exchanges of all the users on his friend-list.<br>
<br>
</div>You can do this but it creates quite a lot of churn on the exchange<br>
layer. �Paul&#39;s suggestion is one way to prevent that. �Another is to<br>
use exchange-exchange bindings, which we are also looking at.<br>
</blockquote></div><div><br>I meant to create bindings to all your online friends. <br>Can you explain how Paul&#39;s suggestion or exchange-exchange bindings solve or improve it? <br></div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br>
<br>
&gt; When user1 want to send a private message or a presence update to user2<br>
&gt; he&#39;ll send it to his own exchange and it&#39;ll be directed to user2. The<br>
&gt; problem with this design is that users without mutual presence subscription<br>
&gt; can&#39;t send private message to each other and can&#39;t send subscription<br>
&gt; requests.<br>
<br>
</div>You can decouple presence, which is about status updates, from<br>
friendship. �If you like, you could have a set up where one user can<br>
DM another, provided they are mutual friends, regardless of who is<br>
online. �Do you want that?<br>
<br>
Subscription requests could also be implemented using a queue - one<br>
per user. �Whenever a new user wishes to request mutual friendship<br>
with user A, then user A could be notified of this via a queue.<br>
</blockquote></div><div><br>In that case will the server send the friendship request directly to the queue?<br>Do you need another queue per user just for friendship requests or can you use the same queue from above?<br>

�</div><div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><br>
<br>
<br>
<br>
&gt; Can you please share your thoughts on the two options and maybe other design<br>
&gt; options?<br>
<br>
</div>I&#39;ve tried to shed some light on some of the issues above. �Feel free<br>
to elaborate on your needs and ask more questions.<br>
<font color="#888888"><br>
alexis<br>
</font><div><div><br>
<br>
<br>
<br>
<br>
&gt; Thanks<br>
&gt; _______________________________________________<br>
&gt; rabbitmq-discuss mailing list<br>
&gt; <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
&gt; <a href="http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div></div></div>