开发者

RabbitMQ with Websocket and Gevent

I'm looking forward to develop a realtime API for my web application using Websocket. For this I'm using RabbitMQ as the broker and My backend is based on python (gevent + websocket),and Pika/Puka as r开发者_开发技巧abbitmq client.

The problem I'm facing here is that, how we can use websocket to connect with rabbitMQ. After the initial websocket connection establishment, the socket object wait for new messages from client, and in the case of rabbitMQ, we need to setup a consumer for it, so it will process the message when it receive one. We can take this in this way,

  1. Clients are established connection with server via full-duplex websocket.
  2. All clients should act as RabbitMQ's consumer after initial websocket handshake, so they all get updates when a client gets some message.
  3. When new message arrives at websocket, that client will send it to RabbitMQ, so at this time this client act as publisher.

The problem is Websocket wait for a new message, and the RabbitMQ consumer wait for new message on its channel, I'm failed to link these two cases.

I'm not sure whether this is a wrong method ...

I'm unable to find a method to implement this scenario.If I'm going wrong way or is there any alternate method ?, please help me to fix this.

Thank you,

Haridas N.


I implemented similar requirement with Tornado + websocket + RabbitMQ + Pika.

I think this were already known method. Here is my git repo for this web chat application.

https://github.com/haridas/RabbitChat

It seems very difficult to the similar thing with gevent/twisted because the rabbitMQ clients couldn't supporting the event loops of gevent/twisted.

The pika has tornado adapter, so that makes this easy to setup. Pika development team working on the twisted adapter also. I hope they will release it very soon.

Thanks,

Haridas N.

http://haridas.in.


A simple solution would be to use gevent.queue.Queue instances for inter-greenlet communication.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜