Trait jsonrpsee_core::middleware::Middleware
source · [−]pub trait Middleware: Send + Sync + Clone + 'static {
type Instant: Send + Copy;
fn on_request(&self) -> Self::Instant;
fn on_connect(&self) { ... }
fn on_call(&self, _name: &str) { ... }
fn on_result(&self, _name: &str, _success: bool, _started_at: Self::Instant) { ... }
fn on_response(&self, _started_at: Self::Instant) { ... }
fn on_disconnect(&self) { ... }
}
Expand description
Defines a middleware with callbacks during the RPC request life-cycle. The primary use case for
this is to collect timings for a larger metrics collection solution but the only constraints on
the associated type is that it be Send
and Copy
, giving users some freedom to do what
they need to do.
See the WsServerBuilder::set_middleware
or the HttpServerBuilder::set_middleware
method
for examples.
Associated Types
Required methods
fn on_request(&self) -> Self::Instant
fn on_request(&self) -> Self::Instant
Called when a new JSON-RPC comes to the server.
Provided methods
fn on_connect(&self)
fn on_connect(&self)
Called when a new client connects (WebSocket only)
Called on each JSON-RPC method call, batch requests will trigger on_call
multiple times.
Called on each JSON-RPC method completion, batch requests will trigger on_result
multiple times.
fn on_response(&self, _started_at: Self::Instant)
fn on_response(&self, _started_at: Self::Instant)
Called once the JSON-RPC request is finished and response is sent to the output buffer.
fn on_disconnect(&self)
fn on_disconnect(&self)
Called when a client disconnects (WebSocket only)