简体   繁体   中英

processing HTTPS requests and ZeroMQ messages in parallel inside Twisted

I am trying to do two things in parallel:

  • intercept HTTPS POST request and make Twisted hold the connection open indefinitely (return NOT_DONE_YET )
  • listen to ZeroMQ queue (and close one of the pending connections as a result of a ZeroMQ message)

I know how to make each of these two things separately, but how can I do them in parallel? To be specific, how can I receive messages from ZeroMQ inside the Twisted framework, when I am already listening to TCP sockets?

You can get support for ZMQ here, in txZMQ .

It sounds like you already know how to deal with the HTTP request.

To do these things in parallel, just create your ZmqSubConnection and your twisted.web.server.Site , with references to each other as necessary for your application. No special set-up is required.

Just make sure you only create and run one reactor. Other people with similar questions sometimes don't understand that reactor.run() means "run the event loop for the whole process", and not "run this one thing I set up".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM