r2d2-nats 0.1.0

Nats support for the r2d2 connection pool
Documentation
  • Coverage
  • 0%
    0 out of 5 items documented0 out of 3 items with examples
  • Size
  • Source code size: 24.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 92.49 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NathanGrimaud

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