pub struct RetryMiddleware { /* private fields */ }Expand description
Retry middleware that implements exponential backoff.
§Examples
use pmcp::shared::{RetryMiddleware, Middleware};
use pmcp::types::{JSONRPCRequest, RequestId};
// Create retry middleware with custom settings
let retry_middleware = RetryMiddleware::new(
5, // max_retries
1000, // initial_delay_ms (1 second)
30000 // max_delay_ms (30 seconds)
);
// Default retry middleware (3 retries, 1s initial, 30s max)
let default_retry = RetryMiddleware::default();
let mut request = JSONRPCRequest {
jsonrpc: "2.0".to_string(),
method: "tools.call".to_string(),
params: Some(serde_json::json!({
"name": "network_tool",
"arguments": {"url": "https://api.example.com/data"}
})),
id: RequestId::from(999i64),
};
// Configure request for retry handling
retry_middleware.on_request(&mut request).await?;
default_retry.on_request(&mut request).await?;
// The actual retry logic would be implemented at the transport levelImplementations§
Trait Implementations§
Source§impl Debug for RetryMiddleware
impl Debug for RetryMiddleware
Source§impl Default for RetryMiddleware
impl Default for RetryMiddleware
Source§impl Middleware for RetryMiddleware
impl Middleware for RetryMiddleware
Source§fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 mut JSONRPCRequest,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 mut JSONRPCRequest,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called before a request is sent.
Source§fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
response: &'life1 mut JSONRPCResponse,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
response: &'life1 mut JSONRPCResponse,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called after a response is received.
Source§fn on_send<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_send<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a message is sent (any type).
Source§fn on_receive<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_receive<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 TransportMessage,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a message is received (any type).
Source§fn on_notification<'life0, 'life1, 'async_trait>(
&'life0 self,
notification: &'life1 mut JSONRPCNotification,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_notification<'life0, 'life1, 'async_trait>(
&'life0 self,
notification: &'life1 mut JSONRPCNotification,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when an unsolicited notification is received. Read more
Auto Trait Implementations§
impl Freeze for RetryMiddleware
impl RefUnwindSafe for RetryMiddleware
impl Send for RetryMiddleware
impl Sync for RetryMiddleware
impl Unpin for RetryMiddleware
impl UnwindSafe for RetryMiddleware
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
Mutably borrows from an owned value. Read more