An Apache Pulsar client library, built with pure rust 🦀 and requires no C++ dependencies.
- Pure Rust, No C++ Dependencies 🦀
- Consumer Client 📥
- Producer Client 📤
- Plugin Support 🔌
- Multi/Dual Consumer & Producer Support 🤝
- TLS Support via rustls 🔐
- Async Resolution of Send & Acks 🪓
- Batching Support 📦
- Automatic Reconnection ♻️
- Automatic Operation Retry 🚀
Using Cargo Add
This will install the newest version of neutron
into your cargo.toml
cargo add neutron
Manually
As this is currently in prerelease you must use the git ssh address directly.
neutron = "0.0.2"
The json
feature provides automatic de/serialization through serde_json
.
neutron = { version = "0.0.2", features = ["json"] }
This is a simple example of a consumer that listens to a topic and prints the message. with the json
feature enabled
use neutron::{ConsumerBuilder, Message};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
#[allow(dead_code)]
struct Data {
name: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let pulsar_config = neutron::PulsarConfig {
endpoint_url: "pulsar://localhost".to_string(),
endpoint_port: 6650,
};
let pulsar = neutron::PulsarBuilder::new()
.with_config(pulsar_config)
.build()
.run();
let consumer = ConsumerBuilder::new()
.with_topic("test")
.with_subscription("test")
.with_consumer_name("test")
.connect(&pulsar)
.await?;
loop {
let response: Message<Data> = consumer.next_message().await?;
log::info!("Received message: {:?}", response.payload);
consumer.ack(&response.ack).await?;
}
}