[rabbitmq-discuss] RabbitMQ with Socket Server

Alex Gentle alexgentle at sify.com
Fri Sep 18 01:40:15 BST 2009

>You need to declare an exchange (of type direct, fanout or topic)

>which acts as the mailbox for sending the message.

Thank you for taking time to answer my questions.

>Once you have parsed the message from socket server and determined it >should go to rabbit, you publish the message to it.

I don’t know Ruby. I wrote a PHP program that parse the message from
socket server and pass the message to RabbitMQ server. When
the message comes back from RabbitMQ, I format it and send to socket
server that forwards the message to iPhone.

The catch here is the performance. iPhone needs to query for the
message in the queue every few seconds. Let us assume
that User A and User B chats thru iPhone application. User A sends the
message to RabbitMQ.

User A -> Socket Server -> RabbitMQ Server

RabbitMQ has no way of sending the notification to User B that some
message is waiting for him.

User B needs to check the RabbitMQ server every 5 seconds to see if
there is any message in his queue.

Imagine there are 10,000 users like user A and B. All of them will be
sending the message thru socket server to RabbitMQ server. Socket
server can handle all the traffic. It’s a piece of cake for RabbitMQ
to handle the traffic. But, the poor PHP program in the middle
(between socket server and RabbitMQ) can’t handle all the incoming and
outgoing requests with ease. It’s going to slow down the process.
Users will see substantial delay in sending and receiving messages.

Is there a better way to do it? Thanks.

On Tue, Sep 15, 2009 at 7:27 PM, Chuck Remes <cremes.devlist at mac.com> wrote:

> On Sep 15, 2009, at 7:19 PM, Alex Gentle wrote:
> > iPhone app -> socket server -> RabbitMQ server
> Great, this is very helpful.
> > iPhone app has some social networking features in addition to the
> > chat component. Think of it like mini-facebook inside iPhone. When a
> > user types a message inside chat window of iPhone app, the message
> > travels to Socket server which directs the message depending on what
> > is on the message header. If the message header says "this message
> > is for RabbitMQ", socket server will route to RabbitMQ. When a
> > message comes from RabbitMQ to socket server, it should have message
> > header that says "Route this to xxxxxx user". Then, socket server
> > will route the message to appropriate user(s).
> >
> > It all looks good, but it doesn't work. Because I don't know how to
> > make a call to RabbitMQ using the message from socket server and how
> > to pass the message from RabbitMQ to socket server in binary format.
> Ah, this is good.
> You need to declare an exchange (of type direct, fanout or topic)
> which acts as the mailbox for sending the message. Once you have
> parsed the message from socket server and determined it should go to
> rabbit, you publish the message to it. Here's some ruby code
> (commented).
> def publish_message_to_rabbit(message)
>   # declare the exchange
>   exchange = MQ.direct 'mailbox'
>   # send the message
>   exchange.publish(message, :key => 'some.routing.key')
> end
> Next, you need to have a client somewhere that is listening for
> messages. You need to allocate a queue to receive the message and
> subscribe to the routing key. Again, some ruby code.
> def listen_for_rabbit_messages
>   # redeclare the exchange; idempotent operation
>   exchange = MQ.direct 'mailbox'
>   # declare a queue to receive the messages
>   queue = MQ.queue 'mailslot'
>   # bind the queue to the exchange and match incoming messages against
>   # the specified routing key
>   queue.bind(exchange, :key => 'some.routing.key').subscribe do |
> message|
>     # this block is called each time a message is received
>     # do your message processing here
>   end
> end
> Does this help? I highly recommend you take a look through the sample
> code and come back with specific questions.
> cr
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090917/4aaa6539/attachment.htm 

More information about the rabbitmq-discuss mailing list