Coder Social home page Coder Social logo

tokio-fluent's Introduction

tokio-fluent

Crates.io Documentation CI

A fluentd client using tokio.

Installation

Add this to your Cargo.toml

[dependencies]
tokio-fluent = "0.5.0"

Example

use std::collections::HashMap;

use tokio_fluent::{Client, Config, FluentClient};
use tokio_fluent::record::{Map, Value};
use tokio_fluent::record_map;

#[tokio::main]
async fn main() {
    // Connect to server using TCP
    let client = Client::new_tcp(
        "127.0.0.1:24224".parse().unwrap(),
        &Config {..Default::default()}
    )
    .await
    .unwrap();
    // Or connecting using unix socket
    let client_unix = Client::new_unix(
        "/path/to/fluentd.sock",
        &Config {..Default::default()}
    )
    .await
    .unwrap();

    // With Map::new()
    let mut map = Map::new();
    map.insert("age".to_string(), 22.into());
    map.insert(
        "scores".to_string(),
        vec![80, 90]
            .into_iter()
            .map(|e| e.into())
            .collect::<Vec<_>>()
            .into(),
    );
    client.send("fluent.test", map).unwrap();

    // With record_map! macro
    let map_from_macro = record_map!(
        "age".to_string() => 22.into(),
        "scores".to_string() => [80, 90].into_iter().map(|e| e.into()).collect::<Vec<_>>().into(),
    );
    client.send("fluent.test", map_from_macro).unwrap();
}

Setting config values

let client = Client::new_tcp(
        "127.0.0.1:24224".parse().unwrap(),
        &Config {..Default::default()}
    )
    .await
    .unwrap();

timeout

Set the timeout value of std::time::Duration to connect to the destination. The default is 3 seconds.

retry_wait

Set the duration of the initial wait for the first retry, in milliseconds. The actual retry wait will be r * 1.5^(N-1) (r: this value, N: the number of retries). The default is 500.

max_retry

Sets the maximum number of retries. If the number of retries become larger than this value, the write/send operation will fail. The default is 10.

max_retry_wait

The maximum duration of wait between retries, in milliseconds. If calculated retry wait is larger than this value, operation will fail. The default is 60,000 (60 seconds).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.