Giacomo Tesio
Giacomo Tesio

Reputation: 7210

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:

  1. 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)?
  2. 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?
  3. 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.

Upvotes: 2

Views: 1028

Answers (1)

djc
djc

Reputation: 11711

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.

Upvotes: 0

Related Questions