zeromq / zmq.rs

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

Is Windows supported? #158

Closed SpaceMonkeyForever closed 2 years ago

SpaceMonkeyForever commented 2 years ago

I'm getting the following error on Windows 10:

toml file:

[dependencies]
zeromq = { version = "*", default-features = false, features = ["async-std-runtime", "all-transport"] }

Error:

5 | use async_std::os::unix::net::{UnixListener, UnixStream};
   |                    ^^^^ could not find `unix` in `os`

If I change toml file to:

[dependencies]
zeromq = "0.3.3"

I get:

2 | use tokio::net::{UnixListener, UnixStream};
  |                  ^^^^^^^^^^^^  ^^^^^^^^^^ no `UnixStream` in `net`
  |                  |
  |                  no `UnixListener` in `net`
  |                  help: a similar name exists in the module: `TcpListener`

It seems like it's always expecting a Unix system

poyea commented 2 years ago

We don't support platforms other than Unix for IPC transport at this point. Would this work?

[dependencies]
zeromq = { version = "*", default-features = false, features = ["async-std-runtime", "tcp-transport"] }
SpaceMonkeyForever commented 2 years ago

That worked for me. Thank you so much! I really wanted to get this to work.

However, I ran into a separate issue. I'm pushing on a PUB socket from Python and I can listen in Rust SUB but when I restart Python PUB, Rust stops receiving data and I have to restart it to re-establish the connection I guess.

I copy pasted the code from stock_client.rs and got rid of async_helpers as the docs suggest:

// mod async_helpers;

use std::convert::TryInto;
use std::env;
use std::error::Error;
use zeromq::{Socket, SocketRecv};
// use async_std::main;

#[async_std::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let args: Vec<String> = env::args().collect();
    let mut subscription = "";
    if args.len() > 1 {
        subscription = &args[1];
    }
    let mut socket = zeromq::SubSocket::new();
    socket
        .connect("tcp://127.0.0.1:3000")
        .await
        .expect("Failed to connect");

    socket.subscribe(subscription).await?;

    loop {
        let recv = socket.recv().await?;
        let str = String::from_utf8(recv.get(0).unwrap().to_vec())?;
        println!("{}", str)
    }
}
poyea commented 2 years ago

Yes, that reconnection feature is missing ATM: #143.

SpaceMonkeyForever commented 2 years ago

I see. I wish this project would get more contributors, I think ZMQ is great. I'm not sure what a good alternative is for easy communication between processes/servers

poyea commented 2 years ago

Not sure if this https://github.com/erickt/rust-zmq helps, but it's not a native version.

SpaceMonkeyForever commented 2 years ago

I'm still not sure how to get that working on Windows, it needs libzmq and I think I have to build that manually. My prod uses Linux but I develop on Windows.

poyea commented 2 years ago

Yes, I believe you need to build libzmq: https://github.com/zeromq/libzmq/blob/master/INSTALL and https://github.com/erickt/rust-zmq#windows-build. This may get tricky depending on your Windows setting. I agree that a native, portable version would be beneficial.

SpaceMonkeyForever commented 2 years ago

I'm not sure why I didn't close this. I was able to get it to run on Windows but I can't remember now what I needed to do.