-
Notifications
You must be signed in to change notification settings - Fork 10
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
Support for streaming multi-part messages #6
Comments
Back when it needed to stream the multipart, I thought it would be useful to use a The proposed methods look reasonable. I also have an idea that maybe we could make socket types generic. So they are able to send/receive messages that satisfy some trait bounds. This should be easier to refactor and the interface would probably still the same (or similar). Btw I do agree we should expand more methods on socket types. For instance, there could be a method for |
I agree about adding a type parameter for the message type. One slightly awkward thing is how ZMQ treats topics. It is reasonable for a topic to be of a different type than the rest of the message parts, but it's also possible for the topic to be the leading bytes of a message. For example you could serialise structs so that the So if I create a |
Sorry for the late reply. It's a busy week for me. Anyway, indeed it's unfortunately that it will have to do something like this. But I guess this is the trade off. I would prefer to just stick with one generic to make it simple IMHO. This also why this crate provides a method to reach inner zmq socket. If someone wants flexibility, he could still find a way to call original socket methods. I'll take some experiments and see how it turns out in next couple of days. |
It definitely needs some thought to get the right balance between simplicity, safety and versatility. One possibility is to have a sensible default for the topic, e.g. |
Yeah, that sounds pretty great! I'm refactoring with generic |
We could also just make the decision to only support topics which are sent as a separate message part. I have no idea how common the other patterns are in the wild, but this would meet my use case. If users want more versatility then we can think about it then. |
Right, let's do this for now since this is also what I need in most of time. What one of trait bound for |
With the release of v0.3.0, it introduces two new types However, I couldn't find a way to make multipart message queue to turn into iterator under the hood yet. Users will have to explicitly use I would prefer to leave this issue open in hope for some enhancement in the future. |
A problem with multipart messages in the current implementation is that senders need to allocate all of the message parts to a
VecDeque
before sending. Likewise, receivers must allocate message parts before they can be processed. Applications such as an XPUB/XSUB proxy would be very inefficient with this API.Ideally, a sender should be able to stream parts from another source, without an intermediate allocation. Receivers should be able to start processing the first part, before the rest arrive.
The API that I am envisioning could look something like this:
socket.send(msg)
can send only single messagessocket.send_multipart(iter)
to send messages from anIntoIterator
socket.send_multipart_stream(stream)
to stream messagessocket.recv()
returns an error if the message is multipartsocket.recv_multipart()
returns aStream
. It works for either multipart or single message.This is quite a big change, which will impact the public API and internal structures. It will need some careful design, and my intention with opening this issue is to trigger some conversation first.
The text was updated successfully, but these errors were encountered: