Module kafka::producer
[−]
[src]
Kafka Producer - A higher-level API for sending messages to kafka topics.
A multi-topic capable producer for a Kafka cluster providing a convenient API for sending messages. So far the producer has only synchronous capabilities.
In Kafka, each message is basically a key/value pair. A Record
is all the data necessary to produce such a message to Kafka.
Example
use std::fmt::Write; use kafka::producer::{Producer, Record}; let mut producer = Producer::from_hosts(vec!("localhost:9092".to_owned())) .with_ack_timeout(1000) .with_required_acks(1) .create() .unwrap(); let mut buf = String::with_capacity(2); for i in 0..10 { let _ = write!(&mut buf, "{}", i); // some computation of the message data to be sent producer.send(&Record::from_value("my-topic", buf.as_bytes())).unwrap(); buf.clear(); }
In this example, when the method call to producer.send
returns
successfully, we are guaranteed the message is delivered to Kafka
and persisted by at least one Kafka broker. However, when sending
multiple messages just like this example, it is more efficient to
send them in batches using Producer::send_all
.
Structs
Builder |
A Kafka Producer builder easing the process of setting up various configuration settings. |
DefaultPartitioner |
As its name implies |
Producer |
The Kafka Producer |
Record |
A structure representing a message to be sent to Kafka through the
|
Topics |
A description of available topics and their available partitions. |
Enums
Compression |
Compression types supported by kafka. The numeral values of this enumeration correspond to the compression encoding in the attributes of a Message in the protocol. |
Constants
DEFAULT_ACK_TIMEOUT |
The default value for |
DEFAULT_REQUIRED_ACKS |
The default value for |
Traits
AsBytes |
A trait used by |
Partitioner |
A partitioner is given a chance to choose/redefine a partition for
a message to be sent to Kafka. See also
|