Crates.io | neutron |
lib.rs | neutron |
version | 0.0.2 |
source | src |
created_at | 2024-03-14 01:03:00.075809 |
updated_at | 2024-04-30 21:55:05.914742 |
description | A Rust client library for Pulsar |
homepage | |
repository | https://github.com/klaatu01/neutron |
max_upload_size | |
id | 1172751 |
size | 227,234 |
An Apache Pulsar client library, built with pure rust 🦀 and requires no C++ dependencies.
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?;
}
}