Struct df_kafka::Kafka

source ·
pub struct Kafka { /* private fields */ }

Implementations§

链接

  • config 配置
{
  "default": "mac",
  "connections": {
    "mac": {
      "brokers": [
        "0.0.0.0:9092"
      ],
      "fetch_max": 900000000,
      "retry_max": 900000000
    }
  }
}
Examples found in repository?
examples/test.rs (line 27)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    env_logger::init();

    let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    root_path = root_path.join("..");
    let conf_path = root_path.join("config");
    let conf_path = conf_path.join("kafka.json");

    let conf = match fs::read_to_string(conf_path) {
        Ok(content) => {
            if content == "" {
                object! {}
            } else {
                json::parse(content.as_str()).unwrap()
            }
        }
        Err(_) => {
            object! {}
        }
    };
    let kafka = Kafka::connect(conf);

    let data = kafka.set("tests", "", "112".into());
    info!(">>>>>>{}", data);
    let data = kafka.set("tests", "", "113".into());
    info!(">>>>>>{}", data);

    let data = kafka.get("tests", "", false);
    info!(">>>>>>{}", data);
}

增加配置

切换配置

生产

Examples found in repository?
examples/test.rs (line 29)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    env_logger::init();

    let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    root_path = root_path.join("..");
    let conf_path = root_path.join("config");
    let conf_path = conf_path.join("kafka.json");

    let conf = match fs::read_to_string(conf_path) {
        Ok(content) => {
            if content == "" {
                object! {}
            } else {
                json::parse(content.as_str()).unwrap()
            }
        }
        Err(_) => {
            object! {}
        }
    };
    let kafka = Kafka::connect(conf);

    let data = kafka.set("tests", "", "112".into());
    info!(">>>>>>{}", data);
    let data = kafka.set("tests", "", "113".into());
    info!(">>>>>>{}", data);

    let data = kafka.get("tests", "", false);
    info!(">>>>>>{}", data);
}

消费

Examples found in repository?
examples/test.rs (line 34)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    env_logger::init();

    let mut root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    root_path = root_path.join("..");
    let conf_path = root_path.join("config");
    let conf_path = conf_path.join("kafka.json");

    let conf = match fs::read_to_string(conf_path) {
        Ok(content) => {
            if content == "" {
                object! {}
            } else {
                json::parse(content.as_str()).unwrap()
            }
        }
        Err(_) => {
            object! {}
        }
    };
    let kafka = Kafka::connect(conf);

    let data = kafka.set("tests", "", "112".into());
    info!(">>>>>>{}", data);
    let data = kafka.set("tests", "", "113".into());
    info!(">>>>>>{}", data);

    let data = kafka.get("tests", "", false);
    info!(">>>>>>{}", data);
}

消费 监听消息不退出

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more