diff --git a/Cargo.lock b/Cargo.lock index 3acf02c..f15577c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,6 +195,15 @@ 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" diff --git a/Cargo.toml b/Cargo.toml index 5045187..a639c61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["api"] +members = ["api", "actix-pubsub"] diff --git a/actix-pubsub/Cargo.toml b/actix-pubsub/Cargo.toml new file mode 100644 index 0000000..cdfaa81 --- /dev/null +++ b/actix-pubsub/Cargo.toml @@ -0,0 +1,10 @@ +[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" } diff --git a/actix-pubsub/src/lib.rs b/actix-pubsub/src/lib.rs new file mode 100644 index 0000000..eb57ccf --- /dev/null +++ b/actix-pubsub/src/lib.rs @@ -0,0 +1,34 @@ +use std::sync::Arc; + +use crossbeam_channel::{Receiver, Sender}; + +struct Message { + topic: Topic, + payload: Payload, +} + +pub trait PubSubBus { + fn publisher(&self) -> Publisher; + + fn subscribe(&self, topic: Topic) -> Subscriber; +} + +pub struct PubSub { + tx: Sender>, + rx: Receiver>, +} + +pub struct Publisher {} + +pub struct Subscriber {} + +impl PubSub { + pub fn new() -> Self { + let (tx, rx) = crossbeam_channel::unbounded::>(); + Self { rx, tx } + } +} + +impl actix::Actor for PubSub { + type Context = actix::Context; +}