zeromq / zmq.rs

A native implementation of ØMQ in Rust
https://crates.io/crates/zeromq
MIT License
1.14k stars 94 forks source link

Monitor sockets #103

Open yan-zaretskiy opened 3 years ago

yan-zaretskiy commented 3 years ago

I'm really excited about this project. Looking forward to dropping the libzmq dependency from my code in favour of zmq.rs. My usage of ZemoMQ is rather lightweight, in fact you already support the features I use (ROUTER/DEALER over TCP). One thing that I think you don't have yet are monitor sockets. I find them very useful when monitoring the connection state. I'm curious whether they are on your Roadmap somewhere in the future? :-)

Alexei-Kornienko commented 3 years ago

I see a following possible solution: 1) create a monitor method on socket. This will create a mpsc channel that will be used to receive monitor events (and give you back a consumer). 2) Create SocketEvent enum for all events (http://api.zeromq.org/4-1:zmq-socket-monitor)

What is not fully clear is what kind of payload should be in this events. Cause for C++ for example spec says "The event value is the file descriptor (FD) of the underlying network socket. Warning: there is no guarantee that the FD is still valid by the time your code receives this event."

I think I will start with some basic implementation of events and we'll have to see what payload actually makes sense for each event type.

yan-zaretskiy commented 3 years ago

I am not at all familiar with zmq.rs yet, so feel free to discard anything I say. The thought I have is that however you choose to signal the monitor events should use the same mechanism that you use for polling other ZeroMQ sockets in your crate, to mimic how it's done in the regular ZeroMQ library.

As for the payload, again, I am a total noob, but judging by that warning, the FD payload is pretty much useless, so perhaps a plain enum without data would suffice.

jfrader commented 2 months ago

Is there any examples on how to check if the connection has dropped? Im trying to figure this out for a while and don't know how to use the monitor