1 个不稳定版本
0.1.0 | 2018年10月2日 |
---|
#35 在 #connection-manager
4KB
60 行
r2d2-nats
此库深受 r2d2-redis 的启发
示例
extern crate r2d2;
extern crate r2d2_nats;
extern crate nats;
use std::thread;
use r2d2_nats::NatsConnectionManager;
fn main() {
let manager = NatsConnectionManager::new("nats://user:[email protected]".to_owned()).unwrap();
let pool = r2d2::Pool::builder().build(manager).unwrap();
let mut handles = vec![];
for _i in 0..10i32 {
let pool = pool.clone();
handles.push(thread::spawn(move || {
let mut conn = pool.get().unwrap();
conn.publish("nats", _i.to_string().as_bytes()).unwrap()
}));
}
for h in handles {
h.join().unwrap();
}
}
依赖项
~5–12MB
~164K SLoC