简体   繁体   English

在Twisted内部并行处理HTTPS请求和ZeroMQ消息

[英]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 ) 拦截HTTPS POST请求并使Twisted无限期保持连接打开(返回NOT_DONE_YET
  • listen to ZeroMQ queue (and close one of the pending connections as a result of a ZeroMQ message) 侦听ZeroMQ队列(并由于ZeroMQ消息而关闭其中一个挂起的连接)

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? 具体来说,当我已经在侦听TCP套接字时,如何从Twisted框架内的ZeroMQ接收消息?

You can get support for ZMQ here, in txZMQ . 您可以在txZMQ中获得对ZMQ的支持。

It sounds like you already know how to deal with the HTTP request. 听起来您已经知道如何处理HTTP请求。

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. 要并行执行这些操作,只需创建ZmqSubConnectiontwisted.web.server.Site ,并在应用程序中根据需要相互引用即可。 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". 遇到类似问题的其他人有时不理解“ reactor.run()意思是“运行整个过程的事件循环”,而不是“运行我设置的这一件事”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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