Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for function callbacks to REQ/REP and PUB/SUB sockets #25

Closed
chuckremes opened this issue May 13, 2010 · 3 comments
Closed

Comments

@chuckremes
Copy link
Contributor

Per a discussion in the comments here: http://www.zeromq.org/blog:multithreaded-server

Expand the 0mq socket api to allow for attaching callbacks to REQ sockets on send. The callback should be invoked when its matching response arrives.

Similarly, allow for attaching callbacks to SUB sockets. All incoming messages should be passed to the callback for processing.

While these features can currently be built on top of the existing api via zmq_poll, it would be cleaner to have it available as part of the supported api.

@zeromq
Copy link
Collaborator

zeromq commented May 13, 2010

In the discussion thread I asked for use case. Haven't got any answer though. In any case, 0MQ cannot provide callbacks because it has no spare thread to call the callback function from.

@chuckremes
Copy link
Contributor Author

I'm going to add this as some syntactic sugar in a new ruby library I am starting up soon.

Briefly, here is my use case. Allow for the creation of multiple reactors (one per thread and context). All send/recv operations are async but are implemented inside of coroutines/fibers/cooperative threads so that they "block." Incoming messages will awaken the coroutine and resume processing.

This allows for writing code in a synchronous style while getting asynchronous performance out of the library.

If this doesn't sound interesting, feel free to close this ticket. I'll send you a pointer to my library as I make progress.

@zeromq
Copy link
Collaborator

zeromq commented May 13, 2010

Yes. It's definitely intereseting, but it should be done outside of core 0MQ library (exactly as you are up to). There are several reasons for that. One of them is that it would require 0MQ to manage a pool of "callback threads". Another is that well-behaved hardcore C library is expected to keep the user in the control rather than controlling the user. Yet another is that callbacks are inherently complex to expose via different languege APIs (bindings). One more: 0MQ's long-term goal is to intergrate messaging with POSIX socket API which has no callbacks.

mrvn pushed a commit to mrvn/libzmq that referenced this issue Jul 2, 2015
benjdero pushed a commit to benjdero/libzmq that referenced this issue Feb 20, 2023
benjdero pushed a commit to benjdero/libzmq that referenced this issue Feb 20, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant