Messagebus crate

This commit is contained in:
eraden 2022-05-01 17:20:31 +02:00
parent 76d592b918
commit 79b67a93a3
5 changed files with 76 additions and 54 deletions

81
Cargo.lock generated
View File

@ -195,15 +195,6 @@ dependencies = [
"twoway",
]
[[package]]
name = "actix-pubsub"
version = "0.1.0"
dependencies = [
"actix 0.13.0",
"actix-rt",
"crossbeam-channel",
]
[[package]]
name = "actix-redis"
version = "0.11.0"
@ -619,6 +610,7 @@ dependencies = [
"jemallocator",
"jwt",
"log",
"messagebus",
"oauth2",
"parking_lot 0.12.0",
"password-hash",
@ -969,6 +961,16 @@ dependencies = [
"typenum",
]
[[package]]
name = "ctor"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "ctr"
version = "0.8.0"
@ -978,6 +980,16 @@ dependencies = [
"cipher",
]
[[package]]
name = "dashmap"
version = "4.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c"
dependencies = [
"cfg-if",
"num_cpus",
]
[[package]]
name = "data-encoding"
version = "2.3.2"
@ -1083,6 +1095,15 @@ dependencies = [
"termcolor",
]
[[package]]
name = "erased-serde"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad132dd8d0d0b546348d7d86cb3191aad14b34e5f979781fc005c80d4ac67ffd"
dependencies = [
"serde",
]
[[package]]
name = "event-listener"
version = "2.5.2"
@ -1796,6 +1817,39 @@ dependencies = [
"autocfg",
]
[[package]]
name = "messagebus"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81124c365f95dc69d0a6e572220dc57ca2d0148fd130bfb2b54a6aa1506102d5"
dependencies = [
"async-trait",
"ctor",
"dashmap",
"erased-serde",
"futures",
"log",
"messagebus_derive",
"parking_lot 0.11.2",
"serde",
"serde_derive",
"sharded-slab",
"smallvec",
"thiserror",
"tokio",
]
[[package]]
name = "messagebus_derive"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f364a3b76588b4997b63e99e1bf73e2cf37e2546e97fbae4cb2a268a74e57e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "mime"
version = "0.3.16"
@ -2767,6 +2821,15 @@ dependencies = [
"digest 0.10.3",
]
[[package]]
name = "sharded-slab"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"

View File

@ -1,2 +1,2 @@
[workspace]
members = ["api", "actix-pubsub"]
members = ["api"]

View File

@ -1,10 +0,0 @@
[package]
name = "actix-pubsub"
version = "0.1.0"
edition = "2021"
[dependencies]
actix = { version = "0.13", features = [] }
actix-rt = { version = "2.7", features = [] }
crossbeam-channel = { version = "0.5" }

View File

@ -1,34 +0,0 @@
use std::sync::Arc;
use crossbeam_channel::{Receiver, Sender};
struct Message<Topic, Payload> {
topic: Topic,
payload: Payload,
}
pub trait PubSubBus<Topic, Payload> {
fn publisher(&self) -> Publisher<Topic, Payload>;
fn subscribe(&self, topic: Topic) -> Subscriber<Topic, Payload>;
}
pub struct PubSub<Topic, Payload> {
tx: Sender<Message<Topic, Payload>>,
rx: Receiver<Message<Topic, Payload>>,
}
pub struct Publisher<Topic, Payload> {}
pub struct Subscriber<Topic, Payload> {}
impl<Topic, Payload> PubSub<Topic, Payload> {
pub fn new() -> Self {
let (tx, rx) = crossbeam_channel::unbounded::<Message<Topic, Payload>>();
Self { rx, tx }
}
}
impl<Topic, Payload> actix::Actor for PubSub<Topic, Payload> {
type Context = actix::Context<Self>;
}

View File

@ -66,3 +66,6 @@ jemallocator = { version = "0.3", features = [] }
sendgrid = { version = "0.17", features = ["async"] }
pay_u = { version = '0.1', features = ["single-client"] }
# For rewrite into bus-based app
messagebus = { version = "0.9.13" }