Synchronous AMQP publish

I know there is a number of libraries, implementing AMQP support in python. What I need, though, is a library, that will allow me to do AMQP publish in a synchronous style, because it will be used from a WSGI app, so the usual asynchronous callback-driven style of interaction with the queue broker will be a bit out of place there.

Other parts of the system use pika for AMQP support, but it is asynchronous and I'd rather not use it even though there is a sort of "blocking" connection there.

Of course, if all else fails, it is possible to maintain a Pika event loop per WSGI process. Another problem is that I've found a couple of nasty (IMO) bugs in the current stable version of Pika and I'd rather use something else.

To reiterate:

  • I need to do basic.publish (with "confirm" support! so that I know when the message is not actually published)
  • In a synchronous fashion
  • To rabbitmq (obviously, "pure" AMQP could also work)
  • From a python WSGI application

  • My understanding is that you can use the RabbitMQ's RPC for synchronous call. As you already have pika in place, there should be no much effort for you to adopt it.


    I'd recommend you check out Kombu which is the underlying library used by Celery. Both Kombu and Celery are commonly and easily integrated with Django and Flask (which is based on Werkzeug) so you shouldn't have any problems integrating it with your WSGI application.


    did you test the example code at pika documentation site?

    There is a section called: Synchronous programming style, no concurrency http://pika.github.com/communicating.html#synchronous-programming-style-no-concurrency

    It looks like what you want is a kind of RPC style call. You can find a good synchronous example at: http://www.rabbitmq.com/tutorials/tutorial-six-python.html

    链接地址: http://www.djcxy.com/p/34196.html

    上一篇: 何时适合使用AMQP?

    下一篇: 同步AMQP发布