-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.rs
70 lines (52 loc) · 1.91 KB
/
storage.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use async_trait::async_trait;
use crate::types::{BrokerAddress, MessageId, SubscriptionInfo, TopicMessage};
#[cfg(feature = "bonsaidb")]
pub mod bonsaidb;
pub mod memory;
#[cfg(feature = "mongodb")]
pub mod mongodb;
#[cfg(feature = "redis")]
pub mod redis;
#[async_trait]
pub trait MetaStorage: Clone + Send + Sync + 'static {
type Error: std::error::Error;
async fn register_topic(
&self,
topic_name: &str,
broker_addr: &BrokerAddress,
) -> Result<(), Self::Error>;
async fn unregister_topic(
&self,
topic_name: &str,
broker_addr: &BrokerAddress,
) -> Result<(), Self::Error>;
async fn get_topic_owner(&self, topic_name: &str)
-> Result<Option<BrokerAddress>, Self::Error>;
async fn add_subscription(&self, info: &SubscriptionInfo) -> Result<(), Self::Error>;
async fn all_subscription(
&self,
topic_name: &str,
) -> Result<Vec<SubscriptionInfo>, Self::Error>;
async fn del_subscription(&self, topic_name: &str, name: &str) -> Result<(), Self::Error>;
async fn get_u64(&self, k: &str) -> Result<Option<u64>, Self::Error>;
async fn put_u64(&self, k: &str, v: u64) -> Result<(), Self::Error>;
async fn inc_u64(&self, k: &str, v: u64) -> Result<u64, Self::Error>;
}
#[async_trait]
pub trait MessageStorage: Clone + Send + Sync + 'static {
type Error: std::error::Error;
async fn put_message(&self, msg: &TopicMessage) -> Result<(), Self::Error>;
async fn get_message(&self, id: &MessageId) -> Result<Option<TopicMessage>, Self::Error>;
async fn del_message(&self, id: &MessageId) -> Result<(), Self::Error>;
async fn save_cursor(
&self,
topic_name: &str,
sub_name: &str,
bytes: &[u8],
) -> Result<(), Self::Error>;
async fn load_cursor(
&self,
topic_name: &str,
sub_name: &str,
) -> Result<Option<Vec<u8>>, Self::Error>;
}