Example for using the pulsar-rs crate to read from a topic
This example also includes reconnect logic to get around a known bug in the Pulsar broker where recovering offloaded data from S3 sometimes causes fetching the next message to hang indefinitely. The reconnect code can be removed if you aren't experiencing this bug in your broker.
- Install Rust
- Install
pkg-configandprotobuf-compiler(compilation will fail and prompt you to install them if they are missing)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt install pkg-config protobuf-compiler
cargo build
cp config.sample.toml config.toml- Fill in the pulsar hostname, port, tenant, namespace, topic, and token in the
config.toml RUST_LOG=info cargo run- Note that the
cargo runwill hang indefinitely in case more messages are sent to the Pulsar topic - Data will be written to
data/{topic_name}.jsonl