pub struct StreamManager { /* private fields */ }Expand description
Enhanced stream manager with resumability support (MCP spec compliant)
Implementations§
Source§impl StreamManager
impl StreamManager
Sourcepub fn new(
storage: Arc<dyn SessionStorage<Error = SessionStorageError>>,
) -> StreamManager
pub fn new( storage: Arc<dyn SessionStorage<Error = SessionStorageError>>, ) -> StreamManager
Create new stream manager with session storage backend
Sourcepub fn with_config(
storage: Arc<dyn SessionStorage<Error = SessionStorageError>>,
config: StreamConfig,
) -> StreamManager
pub fn with_config( storage: Arc<dyn SessionStorage<Error = SessionStorageError>>, config: StreamConfig, ) -> StreamManager
Create stream manager with custom configuration
Sourcepub async fn handle_sse_connection(
&self,
session_id: String,
connection_id: String,
last_event_id: Option<u64>,
) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, StreamError>
pub async fn handle_sse_connection( &self, session_id: String, connection_id: String, last_event_id: Option<u64>, ) -> Result<Response<UnsyncBoxBody<Bytes, Error>>, StreamError>
Handle SSE connection request with proper resumability
Sourcepub async fn register_streaming_connection(
&self,
session_id: &str,
connection_id: String,
sender: Sender<SseEvent>,
) -> Result<(), StreamError>
pub async fn register_streaming_connection( &self, session_id: &str, connection_id: String, sender: Sender<SseEvent>, ) -> Result<(), StreamError>
Register a streaming connection to receive events for a session (public API for POST streaming)
Sourcepub async fn unregister_connection(
&self,
session_id: &str,
connection_id: &String,
)
pub async fn unregister_connection( &self, session_id: &str, connection_id: &String, )
Remove a connection when it’s closed
Sourcepub async fn close_session_connections(&self, session_id: &str) -> usize
pub async fn close_session_connections(&self, session_id: &str) -> usize
Close all SSE connections for a session (useful for session termination)
Sourcepub async fn has_connections(&self, session_id: &str) -> bool
pub async fn has_connections(&self, session_id: &str) -> bool
Check if a session has any active SSE connections
Sourcepub async fn broadcast_to_session(
&self,
session_id: &str,
event_type: String,
data: Value,
) -> Result<u64, StreamError>
pub async fn broadcast_to_session( &self, session_id: &str, event_type: String, data: Value, ) -> Result<u64, StreamError>
Send event to specific session (MCP compliant - ONE connection only)
Sourcepub async fn broadcast_to_session_with_options(
&self,
session_id: &str,
event_type: String,
data: Value,
store_when_no_connections: bool,
) -> Result<u64, StreamError>
pub async fn broadcast_to_session_with_options( &self, session_id: &str, event_type: String, data: Value, store_when_no_connections: bool, ) -> Result<u64, StreamError>
Send event to specific session with option to suppress when no connections exist
Sourcepub async fn broadcast_to_all_sessions(
&self,
event_type: String,
data: Value,
) -> Result<Vec<String>, StreamError>
pub async fn broadcast_to_all_sessions( &self, event_type: String, data: Value, ) -> Result<Vec<String>, StreamError>
Broadcast to all sessions (for server-wide notifications)
Sourcepub async fn cleanup_connections(&self) -> usize
pub async fn cleanup_connections(&self) -> usize
Clean up closed connections
Sourcepub async fn create_post_sse_stream(
&self,
session_id: String,
response: JsonRpcResponse,
) -> Result<Response<BoxBody<Bytes, Infallible>>, StreamError>
pub async fn create_post_sse_stream( &self, session_id: String, response: JsonRpcResponse, ) -> Result<Response<BoxBody<Bytes, Infallible>>, StreamError>
Create SSE stream for POST requests (MCP Streamable HTTP)
Sourcepub async fn subscribe_to_notifications(
&self,
session_id: &str,
notification_types: Vec<String>,
)
pub async fn subscribe_to_notifications( &self, session_id: &str, notification_types: Vec<String>, )
Subscribe a session to specific notification types
Sourcepub async fn unsubscribe_from_notifications(
&self,
session_id: &str,
notification_types: Vec<String>,
)
pub async fn unsubscribe_from_notifications( &self, session_id: &str, notification_types: Vec<String>, )
Unsubscribe a session from specific notification types
Sourcepub async fn is_subscribed(
&self,
session_id: &str,
notification_type: &str,
) -> bool
pub async fn is_subscribed( &self, session_id: &str, notification_type: &str, ) -> bool
Check if a session is subscribed to a specific notification type
Sourcepub async fn get_subscriptions(&self, session_id: &str) -> HashSet<String>
pub async fn get_subscriptions(&self, session_id: &str) -> HashSet<String>
Get all subscriptions for a session
Sourcepub async fn clear_subscriptions(&self, session_id: &str)
pub async fn clear_subscriptions(&self, session_id: &str)
Clear all subscriptions for a session (used during session cleanup)
Sourcepub fn get_config(&self) -> &StreamConfig
pub fn get_config(&self) -> &StreamConfig
Get the stream configuration (for testing and debugging)
Sourcepub async fn get_stats(&self) -> StreamStats
pub async fn get_stats(&self) -> StreamStats
Get statistics about active streams
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StreamManager
impl !RefUnwindSafe for StreamManager
impl Send for StreamManager
impl Sync for StreamManager
impl Unpin for StreamManager
impl !UnwindSafe for StreamManager
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more