2022-07-01 15:51:41 +02:00
|
|
|
use crate::config::ZMQ;
|
2022-05-27 13:59:17 +02:00
|
|
|
|
|
|
|
use zmq;
|
|
|
|
|
|
|
|
const ZMQPROTO: &str = "tcp";
|
|
|
|
|
|
|
|
pub async fn zconnect(zmqcfg: &ZMQ, zmqtype: zmq::SocketType) -> Result<zmq::Socket, zmq::Error> {
|
|
|
|
let zctx = zmq::Context::new();
|
|
|
|
let zmqhost = &zmqcfg.hostname;
|
2022-12-30 20:18:15 +01:00
|
|
|
let zmqport = &zmqcfg.port;
|
2022-05-27 13:59:17 +02:00
|
|
|
let socket = zctx.socket(zmqtype).unwrap();
|
|
|
|
let connectstring = format!("{ZMQPROTO}://{zmqhost}:{zmqport}");
|
|
|
|
socket.connect(&connectstring.as_str())?;
|
|
|
|
Ok(socket)
|
|
|
|
}
|