How to integrate the ASP.NET thread model and ZeroMQ sockets?

I'm building an ASP.NET service (a simple aspx) that requires a REQ call to a ZeroMQ REP node.

So I've to use the REQ/REP pattern, but I can't figure out the proper way to initialize the ZeroMQ context in the ASP.NET pipeline.

Moreover, can I share a single connection among the different ASP.NET threads and if so how?

edit : After some study it looks to me that an inproc router in a dedicated thread should be the way to go, since it would handle sincronization.

But more questions arise:

  • The other end of such an inproc node should be a DEALER? If so, should it connect to the REQ node? Or it should bind to a tcp port and I should code the REP server node to connect to it (the latter would be a bit cumbersome, since I could have different servers exposing the service)?
  • As an alternative, is it correct to build an inproc node bound to a ROUTER socket at one end, and connecting with REQ on the other? If so, should I code the node so that it handles a manual envelop of each message just to be able to send responses back to the correct requesting thread?
  • Is Application_Start the correct pipeline point to initialize the thread handling such router?
  • At the moment a ROUTER/DEALER inproc node that connect to the REQ server looks like the best option, but I'm not sure that it's possibile to connect from a DEALER socket. But this is still just a speculation and could be entirely wrong.


    The zmq_socket manual states:

    ØMQ sockets are not thread safe. Applications MUST NOT use a socket from multiple threads except after migrating a socket from one thread to another with a "full fence" memory barrier.

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

    上一篇: 在zeromq中使用pub / sub + req / rep轮询

    下一篇: 如何整合ASP.NET线程模型和ZeroMQ套接字?