pub struct ServerConfigBuilder { /* private fields */ }
Expand description
The builder to configure and create a JSON-RPC server configuration.
Implementations§
Source§impl ServerConfigBuilder
impl ServerConfigBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ServerConfigBuilder
.
Sourcepub fn max_request_body_size(self, size: u32) -> Self
pub fn max_request_body_size(self, size: u32) -> Self
Set the maximum size of a request body in bytes. Default is 10 MiB.
Sourcepub fn max_response_body_size(self, size: u32) -> Self
pub fn max_response_body_size(self, size: u32) -> Self
Set the maximum size of a response body in bytes. Default is 10 MiB.
Sourcepub fn max_connections(self, max: u32) -> Self
pub fn max_connections(self, max: u32) -> Self
Set the maximum number of connections allowed. Default is 100.
Sourcepub fn max_subscriptions_per_connection(self, max: u32) -> Self
pub fn max_subscriptions_per_connection(self, max: u32) -> Self
Set the maximum number of connections allowed. Default is 1024.
Sourcepub fn set_batch_request_config(self, cfg: BatchRequestConfig) -> Self
pub fn set_batch_request_config(self, cfg: BatchRequestConfig) -> Self
Configure how batch requests shall be handled by the server.
Default: batch requests are allowed and can be arbitrary big but the maximum payload size is limited.
Sourcepub fn custom_tokio_runtime(self, rt: Handle) -> Self
pub fn custom_tokio_runtime(self, rt: Handle) -> Self
Configure a custom tokio::runtime::Handle
to run the server on.
Default: tokio::spawn
Sourcepub fn http_only(self) -> Self
pub fn http_only(self) -> Self
Configure the server to only serve JSON-RPC HTTP requests.
Default: both http and ws are enabled.
Sourcepub fn ws_only(self) -> Self
pub fn ws_only(self) -> Self
Configure the server to only serve JSON-RPC WebSocket requests.
That implies that server just denies HTTP requests which isn’t a WebSocket upgrade request
Default: both http and ws are enabled.
Sourcepub fn set_message_buffer_capacity(self, c: u32) -> Self
pub fn set_message_buffer_capacity(self, c: u32) -> Self
The server enforces backpressure which means that
n
messages can be buffered and if the client
can’t keep with up the server.
This capacity
is applied per connection and
applies globally on the connection which implies
all JSON-RPC messages.
For example if a subscription produces plenty of new items and the client can’t keep up then no new messages are handled.
If this limit is exceeded then the server will “back-off” and only accept new messages once the client reads pending messages.
§Panics
Panics if the buffer capacity is 0.
Sourcepub fn enable_ws_ping(self, config: PingConfig) -> Self
pub fn enable_ws_ping(self, config: PingConfig) -> Self
Enable WebSocket ping/pong on the server.
Default: pings are disabled.
§Examples
use std::{time::Duration, num::NonZeroUsize};
use jsonrpsee_server::{ServerConfigBuilder, PingConfig};
// Set the ping interval to 10 seconds but terminates the connection if a client is inactive for more than 2 minutes
let ping_cfg = PingConfig::new().ping_interval(Duration::from_secs(10)).inactive_limit(Duration::from_secs(60 * 2));
let builder = ServerConfigBuilder::default().enable_ws_ping(ping_cfg);
Sourcepub fn disable_ws_ping(self) -> Self
pub fn disable_ws_ping(self) -> Self
Disable WebSocket ping/pong on the server.
Default: pings are disabled.
Sourcepub fn set_id_provider<I: IdProvider + 'static>(self, id_provider: I) -> Self
pub fn set_id_provider<I: IdProvider + 'static>(self, id_provider: I) -> Self
Configure custom subscription ID
provider for the server to use
to when getting new subscription calls.
You may choose static dispatch or dynamic dispatch because
IdProvider
is implemented for Box<T>
.
Default: RandomIntegerIdProvider
.
§Examples
use jsonrpsee_server::{ServerConfigBuilder, RandomStringIdProvider, IdProvider};
// static dispatch
let builder1 = ServerConfigBuilder::default().set_id_provider(RandomStringIdProvider::new(16));
// or dynamic dispatch
let builder2 = ServerConfigBuilder::default().set_id_provider(Box::new(RandomStringIdProvider::new(16)));
Sourcepub fn set_tcp_no_delay(self, no_delay: bool) -> Self
pub fn set_tcp_no_delay(self, no_delay: bool) -> Self
Configure TCP_NODELAY
on the socket to the supplied value nodelay
.
Default is true
.
Sourcepub fn set_keep_alive(self, keep_alive: Option<Duration>) -> Self
pub fn set_keep_alive(self, keep_alive: Option<Duration>) -> Self
Configure KEEP_ALIVE
hyper to the supplied value keep_alive
.
Sourcepub fn set_keep_alive_timeout(self, keep_alive_timeout: Duration) -> Self
pub fn set_keep_alive_timeout(self, keep_alive_timeout: Duration) -> Self
Configure KEEP_ALIVE_TIMEOUT
hyper to the supplied value keep_alive_timeout
.
Sourcepub fn build(self) -> ServerConfig
pub fn build(self) -> ServerConfig
Build the ServerConfig
.
Trait Implementations§
Source§impl Clone for ServerConfigBuilder
impl Clone for ServerConfigBuilder
Source§fn clone(&self) -> ServerConfigBuilder
fn clone(&self) -> ServerConfigBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more