fn subscriber(url: &str) -> Result<(), nng::Error> {
    let s = Socket::new(Protocol::Sub0)?;
    s.dial(url)?;

    println!("SUBSCRIBER: SUBSCRIBING TO ALL TOPICS");
    let all_topics = vec![];
    s.set_opt::<Subscribe>(all_topics)?;

    loop {
        // Sleep for a little bit before sending the next message.
        thread::sleep(Duration::from_secs(10));

        let connect_psdb = connect_fetch_all_events::main();
        // returns the id
        println!("PUBLISH INSERT EVENT RESPONSE ::  OK? {:?}", connect_psdb);
        // query database
        let msg = s.recv()?;

        let subs = usize::from_le_bytes(msg[..].try_into().unwrap());
        println!("SUBSCRIBER: THERE ARE {} SUBSCRIBERS", subs);

        // // Stick the Flag Message on the event data
        // msg.push_front(b"Message, ");
        // let subs: Subscribe = serde_json::from_slice<'a, Subscribe>(&msg).unwrap();
        // //let subs = usize::nng_msg_header_len(msg);
        // println!("SUBSCRIBERS EVENT DATA {:?} ", subs);

        //s.send(msg)?;
        //Ok(())
    }
}
/// Run the subscriber portion of the program.
Run the subscriber portion of the program.
Run the subscriber portion of the program .
fn subscriber(url: &str) -> Result<(), nng::Error> {
    let s = Socket::new(Protocol::Sub0)?;
    s.dial(url)?;
    println!("SUBSCRIBER: SUBSCRIBING TO ALL TOPICS");
    let all_topics = vec![];
    s.set_opt::<Subscribe>(all_topics)?;
    loop {
        // Sleep for a little bit before sending the next message.
        thread::sleep(Duration::from_secs(10));
        let connect_psdb = connect_fetch_all_events::main();
        // returns the id
        println!("PUBLISH INSERT EVENT RESPONSE ::  OK? {:?}", connect_psdb);
        // query database
        let msg = s.recv()?;
        let subs = usize::from_le_bytes(msg[..].try_into().unwrap());
        println!("SUBSCRIBER: THERE ARE {} SUBSCRIBERS", subs);
        // // Stick the Flag Message on the event data
        // msg.push_front(b"Message, ");
        // let subs: Subscribe = serde_json::from_slice<'a, Subscribe>(&msg).unwrap();
        // //let subs = usize::nng_msg_header_len(msg);
        // println!("SUBSCRIBERS EVENT DATA {:?} ", subs);
        //s.send(msg)?;
        //Ok(())
    }
}
fn subscriber ( url : & str ) -> Result < ( ) , nng :: Error > { let s = Socket :: new ( Protocol :: Sub0 ) ? ; s . dial ( url ) ? ; println ! ( " " ) ; let all_topics = vec ! [ ] ; s . set_opt :: < Subscribe > ( all_topics ) ? ; loop { // Sleep for a little bit before sending the next message. thread :: sleep ( Duration :: from_secs ( 10 ) ) ; let connect_psdb = connect_fetch_all_events :: main ( ) ; // returns the id println ! ( " " connect_psdb ) ; // query database let msg = s . recv ( ) ? ; let subs = usize :: from_le_bytes ( msg [ .. ] . try_into ( ) . unwrap ( ) ) ; println ! ( " " subs ) ; // // Stick the Flag Message on the event data // msg.push_front(b"Message, "); // let subs: Subscribe = serde_json::from_slice<'a, Subscribe>(&msg).unwrap(); // //let subs = usize::nng_msg_header_len(msg); // println!("SUBSCRIBERS EVENT DATA {:?} ", subs); //s.send(msg)?; //Ok(()) } }
Run the subscriber portion of the program.
Run the subscriber portion of the program .
url
&str