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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Server-Sent Events (SSE) transport for exchange data streaming.
//!
//! This module provides an SSE-based transport implementation with support for:
//!
//! - **Event Streaming**: Receive real-time updates via SSE connections using
//! the inlined SSE parser for spec-compliant SSE parsing.
//! - **Auto-Reconnection**: Reliable connections with configurable exponential
//! backoff, `Last-Event-ID` tracking, and maximum attempt limits.
//! - **Protocol Abstraction**: Exchange-agnostic via the [`SseProtocolHandler`]
//! trait — classify events, hook into lifecycle events, and control retry
//! behaviour per-exchange.
//! - **Authentication**: Optional request signing via
//! [`Authentication`](crate::auth::Authentication) on every connection and
//! reconnection.
//! - **Connection/Handle/Stream Split**: Mirrors the WebSocket module's
//! [`Connection`](crate::websocket::Connection) pattern — spawn a background
//! task, then interact via clone-able [`SseHandle`] and consumable
//! [`SseStream`].
//!
//! # Architecture
//!
//! ```text
//! SseConnection::connect(config, handler)
//! └─ spawns background task ──► tokio::spawn(sse_connection_driver)
//! │ │
//! ├── SseHandle ◄─── mpsc ◄──────┤ (commands: Close, Reconnect)
//! │ │
//! └── SseStream ◄─── mpsc ◄──────┘ (SseEvent items)
//! ```
//!
//! # Quick Start
//!
//! ```rust,no_run
//! use std::time::Duration;
//!
//! use hpx_transport::sse::{
//! SseConfig, SseConnection, SseMessageKind, handlers::GenericSseHandler,
//! };
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let config = SseConfig::new("https://api.exchange.com/v1/stream")
//! .connect_timeout(Duration::from_secs(10))
//! .reconnect_max_attempts(Some(5));
//!
//! let handler = GenericSseHandler::new();
//! let connection = SseConnection::connect(config, handler).await?;
//! let (handle, mut stream) = connection.split();
//!
//! while let Some(event) = stream.next_event().await {
//! match event.kind {
//! SseMessageKind::Data => {
//! println!("type={} data={}", event.event_type(), event.data());
//! }
//! _ => {}
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! # Module Index
//!
//! | Module | Description |
//! |--------|-------------|
//! | `config` | [`SseConfig`] builder for connection settings |
//! | [`connection`] | [`SseConnection`], [`SseHandle`], [`SseStream`] |
//! | `protocol` | [`SseProtocolHandler`] trait |
//! | `types` | [`SseEvent`], [`SseMessageKind`] |
//! | [`handlers`] | Ready-to-use handlers ([`GenericSseHandler`](handlers::GenericSseHandler)) |
// Re-export config types
pub use SseConfig;
// Re-export connection types
pub use ;
// Re-export inlined SSE parser types
pub use ;
// Re-export protocol types
pub use SseProtocolHandler;
// Re-export core types
pub use ;