pub struct PubSubManager { /* private fields */ }Expand description
Pub/Sub Manager interface
Uses StreamableHTTP protocol for all operations.
Pub/Sub is reactive by default - use subscribe() and subscribe_topic().
Implementations§
Source§impl PubSubManager
impl PubSubManager
Sourcepub async fn publish(
&self,
topic: &str,
data: Value,
priority: Option<u8>,
headers: Option<HashMap<String, String>>,
) -> Result<usize>
pub async fn publish( &self, topic: &str, data: Value, priority: Option<u8>, headers: Option<HashMap<String, String>>, ) -> Result<usize>
Sourcepub async fn subscribe_topics(
&self,
subscriber_id: &str,
topics: Vec<String>,
) -> Result<String>
pub async fn subscribe_topics( &self, subscriber_id: &str, topics: Vec<String>, ) -> Result<String>
Subscribe to topics
Supports wildcard patterns:
user.*- single-level wildcarduser.#- multi-level wildcard
§Returns
Returns a subscription ID
Sourcepub async fn unsubscribe(
&self,
subscriber_id: &str,
topics: Vec<String>,
) -> Result<()>
pub async fn unsubscribe( &self, subscriber_id: &str, topics: Vec<String>, ) -> Result<()>
Unsubscribe from topics
Sourcepub async fn list_topics(&self) -> Result<Vec<String>>
pub async fn list_topics(&self) -> Result<Vec<String>>
List all active topics
Source§impl PubSubManager
impl PubSubManager
Sourcepub fn observe(
&self,
subscriber_id: impl Into<String>,
topics: Vec<String>,
) -> (impl Stream<Item = PubSubMessage> + 'static, SubscriptionHandle)
pub fn observe( &self, subscriber_id: impl Into<String>, topics: Vec<String>, ) -> (impl Stream<Item = PubSubMessage> + 'static, SubscriptionHandle)
Observe messages from Pub/Sub topics reactively using WebSocket
Returns a Stream of messages that are delivered in real-time via WebSocket. Supports wildcard patterns:
user.*- single-level wildcarduser.#- multi-level wildcard
§Arguments
subscriber_id- Unique subscriber identifiertopics- List of topics to subscribe to (supports wildcards)
§Example
use futures::StreamExt;
use synap_sdk::{SynapClient, SynapConfig};
let (mut stream, handle) = client.pubsub()
.observe("subscriber-1", vec!["user.*".to_string(), "events.#".to_string()]);
// Process messages reactively
while let Some(message) = stream.next().await {
tracing::info!("Received on {}: {:?}", message.topic, message.data);
}
// Stop subscribing
handle.unsubscribe();Sourcepub fn observe_topic(
&self,
subscriber_id: impl Into<String>,
topic: impl Into<String>,
) -> (impl Stream<Item = PubSubMessage> + 'static, SubscriptionHandle)
pub fn observe_topic( &self, subscriber_id: impl Into<String>, topic: impl Into<String>, ) -> (impl Stream<Item = PubSubMessage> + 'static, SubscriptionHandle)
Observe messages from a single topic reactively
Convenience method for subscribing to a single topic.
§Example
use futures::StreamExt;
use synap_sdk::{SynapClient, SynapConfig};
let (mut stream, handle) = client.pubsub()
.observe_topic("subscriber-1", "user.events");
while let Some(message) = stream.next().await {
tracing::info!("Received: {:?}", message);
}
handle.unsubscribe();Trait Implementations§
Source§impl Clone for PubSubManager
impl Clone for PubSubManager
Source§fn clone(&self) -> PubSubManager
fn clone(&self) -> PubSubManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PubSubManager
impl !RefUnwindSafe for PubSubManager
impl Send for PubSubManager
impl Sync for PubSubManager
impl Unpin for PubSubManager
impl UnsafeUnpin for PubSubManager
impl !UnwindSafe for PubSubManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more