18 releases

0.2.18 Jul 8, 2024
0.2.17 Jul 8, 2024
0.2.16 Jun 7, 2024
0.2.13 May 21, 2024
0.2.1 Mar 15, 2021

#305 in Database interfaces

Download history 12/week @ 2024-03-29 7/week @ 2024-04-05 4/week @ 2024-04-12 124/week @ 2024-04-26 502/week @ 2024-05-03 202/week @ 2024-05-10 327/week @ 2024-05-17 43/week @ 2024-05-24 74/week @ 2024-05-31 344/week @ 2024-06-07 11/week @ 2024-06-14 1/week @ 2024-06-21 18/week @ 2024-06-28 299/week @ 2024-07-05 23/week @ 2024-07-12

341 downloads per month

MIT license

16KB
175 lines

changes_stream2

License Cargo Documentation

Fork of https://github.com/ashleygwilliams/changes-stream-rust / https://crates.io/crates/changes-stream.

An implementation of changes-stream in Rust.

This code reads in a readable stream from an endpoint, parses each line and returns CouchDB changes events as defined in src/event.rs.

usage

in your Cargo.toml:

[dependencies]
changes-stream2 = "0.2"

from examples/follower.rs:

use changes_stream2::{ChangesStream, Event};
use futures_util::stream::StreamExt;

#[tokio::main]
async fn main() {
    let url = "https://replicate.npmjs.com/_changes".to_string();
    let mut changes = ChangesStream::new(url).await.unwrap();
    while let Some(event) = changes.next().await {
        match event {
            Ok(Event::Change(change)) => println!("Change ({}): {}", change.seq, change.id),
            Ok(Event::Finished(finished)) => println!("Finished: {}", finished.last_seq),
            Err(err) => println!("Error: {:?}", err),
        }
    }
}

features

metrics

Enables metrics collection of the changes stream as counter values. The name is generated from the host and path of the url(database name). The metrics are:

  • couchdb_changes_{name}_bytes: Total bytes read from the changes stream
  • couchdb_changes_{name}_entries: Total parsed change entries

raw_value_doc

Changes the type of ChangeEvent::Doc from serde_json::Map<String, serde_json::Value> to serde_json::value::RawValue.

native-tls

Use the native-tls crate for TLS connections. This is the default.

rustls-tls

Use the rustls crate for TLS connections.

Dependencies

~6–17MB
~252K SLoC