#connection-pool #nats #pool #connection-manager #natsio

r2d2-nats

Nats support for the r2d2 connection pool

1 unstable release

0.1.0 Oct 2, 2018

#32 in #connection-manager

MIT license

4KB
60 lines

r2d2-nats

rust-nats support library for the r2d2 connection pool.

This library is strongly inspired by r2d2-redis

Example

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:password@127.0.0.1".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();
    }
}

Dependencies

~6–13MB
~153K SLoC