vertx_tcp_eventbus_bridge_client_rust/lib.rs
1//! # A future based vert.x tcp eventbus client implementation for Rust.
2//! `Eventbus` is the core struct to communicate with [vert.x](https://vertx.io/) eventbus.
3//! Any further operation can be represented by a stream or future.
4//! The body of a message is a json value [serde_json::value](https://docs.serde.rs/serde_json/value/enum.Value.html)
5//! # Example
6//! ```
7//! let task = future::Eventbus::connect(IpAddr::from_str("127.0.0.1").unwrap(), 12345);
8//! let task = task.and_then(|(eventbus, readstream, writestream)| {
9//! tokio::spawn(readstream.into_future().map(|_| ()).map_err(|e| ()));
10//! tokio::spawn(writestream.into_future().map(|_| ()).map_err(|e| ()));
11//! futures::future::ok(eventbus)
12//! });
13//! let task = task.and_then(|eventbus: Eventbus| {
14//! let test_reply = eventbus.send_reply("test".to_string(), json!({
15//! "aaaa":"bbbb"
16//! })).unwrap().and_then(|response| {
17//! println!("{:?}", response);
18//! futures::future::ok(())
19//! });
20//! test_reply
21//! });
22//! tokio::run(task.map_err(|e| ()));
23//! ```
24extern crate byteorder;
25extern crate bytes;
26extern crate crossbeam;
27#[macro_use]
28extern crate serde_derive;
29#[macro_use]
30extern crate serde_json;
31
32pub mod response;
33pub mod request;
34pub mod future;
35pub mod codec;
36
37#[cfg(test)]
38mod tests {
39 use std::net::IpAddr;
40 use std::str::FromStr;
41
42 use futures::future::{Future, IntoFuture};
43 use tokio::prelude::stream::Stream;
44
45 use crate::future;
46 use crate::future::Eventbus;
47
48 /// Current Output:
49 /// running 1 test
50 /// MessageFail(ResponseFailObject { failureCode: 1, failureType: "RECIPIENT_FAILURE", message: "test fail message", sourceAddress: "test" })
51 #[test]
52 fn test_send() {
53 let task = future::Eventbus::connect(IpAddr::from_str("127.0.0.1").unwrap(), 12345);
54 let task = task.and_then(|(eventbus, readstream, writestream)| {
55 tokio::spawn(readstream.into_future().map(|_| ()).map_err(|e| ()));
56 tokio::spawn(writestream.into_future().map(|_| ()).map_err(|e| ()));
57 futures::future::ok(eventbus)
58 });
59 let task = task.and_then(|eventbus: Eventbus| {
60 let test_reply = eventbus.send_reply("test".to_string(), json!({
61 "aaaa":"bbbb"
62 })).unwrap().and_then(|response| {
63 println!("{:?}", response);
64 futures::future::ok(())
65 });
66 test_reply
67 });
68 tokio::run(task.map_err(|e| ()));
69 }
70}