diff --git a/msg-socket/src/pub/socket.rs b/msg-socket/src/pub/socket.rs index 2e84c1a..bc5a7f9 100644 --- a/msg-socket/src/pub/socket.rs +++ b/msg-socket/src/pub/socket.rs @@ -102,6 +102,25 @@ impl PubSocket { { debug!("No active subscriber sessions"); } + + Ok(()) + } + + /// Publishes a message to the given topic. If the topic doesn't exist, this is a no-op. + pub fn try_publish(&self, topic: String, message: Bytes) -> Result<(), PubError> { + let msg = PubMessage::new(topic, message); + + // Broadcast the message directly to all active sessions. + if self + .to_sessions_bcast + .as_ref() + .ok_or(PubError::SocketClosed)? + .send(msg) + .is_err() + { + debug!("No active subscriber sessions"); + } + Ok(()) }