Last active
November 12, 2021 14:38
-
-
Save digizeph/90d5a88c1016b9be0bd2001b8c1318d0 to your computer and use it in GitHub Desktop.
Example code for parsing RIS-Live JSON messages using BGPKIT Parser (https://github.com/bgpkit/bgpkit-parser).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use bgpkit_parser::parse_ris_live_message; | |
| use serde_json::json; | |
| use tungstenite::{connect, Message}; | |
| use url::Url; | |
| const RIS_LIVE_URL: &str = "ws://ris-live.ripe.net/v1/ws/?client=rust-bgpkit-parser"; | |
| /// This is an example of subscribing to RIS-Live's streaming data from one host (`rrc21`). | |
| /// | |
| /// For more RIS-Live details, check out their documentation at https://ris-live.ripe.net/manual/ | |
| fn main() { | |
| // connect to RIPE RIS Live websocket server | |
| let (mut socket, _response) = | |
| connect(Url::parse(RIS_LIVE_URL).unwrap()) | |
| .expect("Can't connect to RIS Live websocket server"); | |
| // subscribe to messages from one collector | |
| let msg = json!({"type": "ris_subscribe", "data": {"host": "rrc21"}}).to_string(); | |
| socket.write_message(Message::Text(msg)).unwrap(); | |
| loop { | |
| let msg = socket.read_message().expect("Error reading message").to_string(); | |
| if let Ok(elems) = parse_ris_live_message(msg.as_str()) { | |
| for elem in elems { | |
| println!("{}", elem); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment