pub struct EventStreamWriter { /* private fields */ }Expand description
Producer helper for a streaming HTTP response — thin sugar over plain
event sends to the caller’s reply route (Java EventStreamWriter).
Implementations§
Source§impl EventStreamWriter
impl EventStreamWriter
Sourcepub fn new(
platform: &Platform,
reply_to: &str,
correlation_id: Option<&str>,
) -> Result<Self, AppError>
pub fn new( platform: &Platform, reply_to: &str, correlation_id: Option<&str>, ) -> Result<Self, AppError>
Create a writer for a reply route and correlation id.
Returns HTTP-400 when the reply route is empty — a streaming producer without a reply address has nowhere to stream.
Sourcepub fn from_request(
platform: &Platform,
request: &EventEnvelope,
) -> Result<Self, AppError>
pub fn from_request( platform: &Platform, request: &EventEnvelope, ) -> Result<Self, AppError>
Create a writer from the incoming request envelope (the usual form for an interceptor function).
Sourcepub fn first(&mut self, status: i32, content_type: &str) -> &mut Self
pub fn first(&mut self, status: i32, content_type: &str) -> &mut Self
Optional head control carried by the first outgoing event: response status and content type. Later events cannot change the head.
Sourcepub fn first_with_ttl(
&mut self,
status: i32,
content_type: &str,
ttl_seconds: u64,
) -> &mut Self
pub fn first_with_ttl( &mut self, status: i32, content_type: &str, ttl_seconds: u64, ) -> &mut Self
Head control plus an idle-allowance override in seconds between
segments (rides the first event as the x-ttl envelope header).
Sourcepub async fn write<T: Serialize>(&mut self, segment: T) -> Result<(), AppError>
pub async fn write<T: Serialize>(&mut self, segment: T) -> Result<(), AppError>
Send one data segment (String, bytes or map — any serializable body).
Sourcepub async fn write_named<T: Serialize>(
&mut self,
event_name: &str,
segment: T,
) -> Result<(), AppError>
pub async fn write_named<T: Serialize>( &mut self, event_name: &str, segment: T, ) -> Result<(), AppError>
Send one named segment — the name maps to the SSE event: field.
Sourcepub async fn close_with<T: Serialize>(
&mut self,
metadata: T,
) -> Result<(), AppError>
pub async fn close_with<T: Serialize>( &mut self, metadata: T, ) -> Result<(), AppError>
Declare end of transmission with trailing metadata (rendered as the terminal SSE event’s data; ignored in chunked mode).