Skip to main content

Stream

Struct Stream 

Source
pub struct Stream { /* private fields */ }
Expand description

Stream represents a realtime report stream. Safe for concurrent usage. When HA mode is enabled and at least 2 origins are provided, the Stream will maintain at least 2 concurrent connections to different instances to ensure high availability, fault tolerance and minimize the risk of report gaps.

Implementations§

Source§

impl Stream

Source

pub async fn new( config: &Config, feed_ids: Vec<ID>, ) -> Result<Stream, StreamError>

Establishes a streaming WebSocket connection that sends reports for the given feedID(s) after they are verified.

§Arguments
  • config - A validated Config instance.
  • feedIDs - A comma-separated list of Data Streams feed IDs.
§Endpoint:
/api/v1/ws
§Type:
  • WebSocket
§Sample Request:
GET /api/v1/ws?feedIDs=<feedID1>,<feedID2>,...
§Sample Response:
{
    "report": {
        "feedID": "Hex encoded feedId.",
        "fullReport": "A blob containing the report context and body. Encode the fee token into the payload before passing it to the contract for verification.",
        "validFromTimestamp": "Report's earliest applicable timestamp (in seconds).",
        "observationsTimestamp": "Report's latest applicable timestamp (in seconds)."
    }
}
§Error Response Codes
Status CodeDescription
400 Bad RequestThis error is triggered when:
- There is any missing/malformed query argument.
- Required headers are missing or provided with incorrect values.
401 Unauthorized UserThis error is triggered when:
- Authentication fails, typically because the HMAC signature provided by the client doesn’t match the one expected by the server.
- A user requests access to a feed without the appropriate permission or that does not exist.
500 Internal ServerIndicates an unexpected condition encountered by the server, preventing it from fulfilling the request. This error typically points to issues on the server side.
Source

pub async fn listen(&mut self) -> Result<(), StreamError>

Starts listening for reports on the Stream. This method will spawn a new task for each WebSocket connection.

Source

pub async fn read(&mut self) -> Result<WebSocketReport, StreamError>

Reads the next available report on the Stream. Reads blocks until a report is received, the context is canceled or all underlying connections are in a error state.

§Returns
  • WebSocketReport - The next available report.
Source

pub async fn close(&mut self) -> Result<(), StreamError>

Closes the Stream. It is the caller’s responsibility to call close when the stream is no longer needed.

Source

pub fn get_stats(&self) -> StatsSnapshot

Returns basic stats about the Stream.

§Returns
  • StatsSnapshot - A snapshot of the current Stream statistics.
    • accepted - Total number of accepted reports.
    • deduplicated - Total number of deduplicated reports when in HA.
    • total_received - Total number of received reports.
    • partial_reconnects - Total number of partial reconnects when in HA.
    • full_reconnects - Total number of full reconnects.
    • configured_connections - Number of configured connections if in HA.
    • active_connections - Current number of active connections.

Auto Trait Implementations§

§

impl !Freeze for Stream

§

impl !RefUnwindSafe for Stream

§

impl Send for Stream

§

impl Sync for Stream

§

impl Unpin for Stream

§

impl UnsafeUnpin for Stream

§

impl !UnwindSafe for Stream

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,