some documentation and package changes

This commit is contained in:
Barna Máté 2024-11-25 06:38:07 +01:00
parent d1c583e997
commit 6b57e96e84
4 changed files with 10 additions and 38 deletions

View file

@ -1,12 +1,12 @@
[package] [package]
name = "bunbun-worker" name = "bunbun-worker"
version = "0.2.1" version = "0.2.2"
description = "An rpc/non-rpc rabbitmq worker library" description = "An rpc/non-rpc AMQP worker library"
edition = "2021" edition = "2021"
license = "AGPL-3.0" license = "AGPL-3.0"
authors = ["4o1x5 <4o1x5@4o1x5.dev>"] authors = ["4o1x5 <4o1x5@4o1x5.dev>"]
repository = "https://git.4o1x5.dev/4o1x5/bunbun-worker" repository = "https://git.4o1x5.dev/4o1x5/bunbun-worker"
keywords = ["worker", "rpc", "rabbitmq"] keywords = ["worker", "rpc", "rabbitmq", "amqp"]
[dependencies] [dependencies]

View file

@ -1,11 +1,8 @@
<center> <h1> BunBun-Worker </h1> </center> <center> <h1> BunBun-Worker </h1> </center>
> ❗ Disclaimer
> This crate is still under development, meaning api's may change on every commit...
# Introduction # Introduction
`bunbun-worker` was made to provide a _panic-safe_ multithreaded job-runner server & client for microservices and alike. It supports [RPC](https://wikipedia.org/wiki/Remote_procedure_call) and regular (non-rpc) calls. As of right now only [rabbitmq](https://www.rabbitmq.com/) is supported but [gRPC](https://grpc.io/) will be added too. `bunbun-worker` is a bare-bone simple multithreaded worker & client library.
The creator of this crate recommends against using this library in production as it's a rather a proof of concept. If you intend to use RPC, I highly recommend using a crate like [tonic](https://crates.io/crates/tonic).
### Rpc ### Rpc
@ -168,11 +165,6 @@ let result = client
.unwrap(); .unwrap();
``` ```
# Limitations
1. Currently some `unwrap()`'s are called inside the code and may results in panics (not in the job-runner).
2. limited API
# Bugs department # Bugs department
Since the code is hosted on a private git instance (as of right now) any bugs shall be discussed in [4o1x5's project room](https://matrix.to/#/#projects:4o1x5.dev). Since the code is hosted on a private git instance (as of right now) any bugs shall be discussed in [4o1x5's project room](https://matrix.to/#/#projects:4o1x5.dev).

View file

@ -24,7 +24,7 @@ pub struct Client {
// TODO implement tls // TODO implement tls
impl Client { impl Client {
/// Creates an rpc client /// Creates an `bunbun-worker` client.
/// ///
/// # Examples /// # Examples
/// ///
@ -72,7 +72,6 @@ impl Client {
.await .await
.unwrap(); .unwrap();
// TODO handle errors
tracing::debug!( tracing::debug!(
"Creating consumer to listen for error/result messages {}", "Creating consumer to listen for error/result messages {}",
callback_queue.name() callback_queue.name()
@ -137,7 +136,6 @@ impl Client {
error, error,
now.elapsed() now.elapsed()
); );
// Idk if i should nack it?
return Err(ClientError::FailedDecode); return Err(ClientError::FailedDecode);
} }
Ok(del) => { Ok(del) => {
@ -292,6 +290,7 @@ pub struct BasicCallOptions {
message_version: String, message_version: String,
} }
impl BasicCallOptions { impl BasicCallOptions {
/// Create a default BasicCallOptions object by using a queue name.
pub fn default(queue_name: impl Into<String>) -> Self { pub fn default(queue_name: impl Into<String>) -> Self {
Self { Self {
timeout: None, timeout: None,
@ -299,10 +298,12 @@ impl BasicCallOptions {
message_version: "v1.0.0".into(), message_version: "v1.0.0".into(),
} }
} }
/// Set the version of the message, by appending `message_version` after `queue_name`
pub fn message_version(mut self, message_version: impl Into<String>) -> Self { pub fn message_version(mut self, message_version: impl Into<String>) -> Self {
self.message_version = message_version.into(); self.message_version = message_version.into();
self self
} }
/// Set the timeout interval on how long the client shall listen to on the callback queue.
pub fn timeout(mut self, timeout: Duration) -> Self { pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = Some(timeout); self.timeout = Some(timeout);
self self

View file

@ -109,7 +109,7 @@ impl WorkerConfig {
} }
} }
/// A worker configuration /// A listener's configuration.
pub struct ListenerConfig { pub struct ListenerConfig {
prefetch_count: u16, prefetch_count: u16,
@ -720,27 +720,6 @@ impl Display for ResultHeader {
} }
} }
async fn create_consumer(
channel: Channel,
queue_name: &str,
consumer_tag: &str,
prefect_count: u16,
) -> Result<Consumer, lapin::Error> {
let channel = channel.clone();
channel
.basic_qos(prefect_count, BasicQosOptions::default())
.await?;
channel
.basic_consume(
queue_name,
consumer_tag,
BasicConsumeOptions::default(),
FieldTable::default(),
)
.await
}
async fn set_consumer_qos(channel: &mut Channel, prefetch_count: u16) -> Result<(), lapin::Error> { async fn set_consumer_qos(channel: &mut Channel, prefetch_count: u16) -> Result<(), lapin::Error> {
channel channel
.basic_qos(prefetch_count, BasicQosOptions::default()) .basic_qos(prefetch_count, BasicQosOptions::default())