r2d2-nats 0.1.0

Nats support for the r2d2 connection pool
Documentation

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();
    }
}