celp_sdk/broker/
interface.rs

1use std::result::Result;
2
3use crate::protobuf::system_event::Severity;
4
5/// Message returned by an object implementing the Subscribe trait
6pub struct Message {
7    pub data: Vec<u8>,
8    pub topic: String,
9}
10
11/// Publish trait: defines the publish behaviour for an object implementing it. It provides short hands for
12/// publishing protobuf messages and system events
13pub trait Publish {
14    type Error;
15
16    fn publish<M: prost::Message>(&mut self, topic: &str, message: &M) -> Result<(), Self::Error>;
17    fn publish_with_cache<M: prost::Message>(
18        &mut self,
19        topic: &str,
20        message: &M,
21    ) -> Result<(), Self::Error>;
22
23    fn publish_event<E: prost::Message + prost::Name>(
24        &mut self,
25        event_details: &E,
26        severity: Severity,
27    ) -> Result<(), Self::Error>;
28
29    fn publish_raw(&mut self, topic: &str, data: &[u8]) -> Result<(), Self::Error>;
30}
31
32/// Publish trait: defines the subscribe behaviour for an object implementing it. It provides short hands for
33/// subscribing to system events
34pub trait Subscribe {
35    type Error;
36
37    fn subscribe(&mut self, topic: &str) -> Result<Option<Message>, Self::Error>;
38    fn subscribe_pattern(&mut self, pattern: &str) -> Result<(), Self::Error>;
39    fn subscribe_event<E: prost::Message + prost::Name>(
40        &mut self,
41    ) -> Result<Option<Message>, Self::Error>;
42
43    fn unsubscribe(&mut self, topic: &str) -> Result<(), Self::Error>;
44    fn unsubscribe_pattern(&mut self, pattern: &str) -> Result<(), Self::Error>;
45    fn unsubscribe_event<E: prost::Message + prost::Name>(&mut self) -> Result<(), Self::Error>;
46
47    fn get_message(&mut self) -> Result<Message, Self::Error>;
48}