2 releases

0.0.2 Apr 30, 2024
0.0.1 Mar 14, 2024

#1975 in Parser implementations

Download history 18/week @ 2024-09-22 1/week @ 2024-09-29

94 downloads per month

MIT license

120KB
3.5K SLoC

Neutron - This package is currently a Work In Progress and is NOT Production Ready

An Apache Pulsar client library, built with pure rust 🦀 and requires no C++ dependencies.

Features:

  • 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 🚀

Installation

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"

Features

The json feature provides automatic de/serialization through serde_json.

neutron = { version = "0.0.2", features = ["json"] }

Example

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?;
    }
}

Dependencies

~16–30MB
~474K SLoC