Skip to content

Commit

Permalink
refactor(server): user ServerConfigBuilder to replace Builder's dupli…
Browse files Browse the repository at this point in the history
…cate setter methods

BREAKING CHANGE:

- add `custom_tokio_runtime` method for `ServerConfigBuilder`

- remove all config setter methods of `ServerBuilder`
- add `with_config` constructor for `ServerBuilder`
- add `set_config` method for `ServerBuilder`
  • Loading branch information
koushiro committed Oct 30, 2024
1 parent be2a71b commit 1d7e0a9
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 221 deletions.
6 changes: 4 additions & 2 deletions examples/examples/jsonrpsee_as_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ use jsonrpsee::core::async_trait;
use jsonrpsee::http_client::HttpClient;
use jsonrpsee::proc_macros::rpc;
use jsonrpsee::server::middleware::rpc::{ResponseFuture, RpcServiceBuilder, RpcServiceT};
use jsonrpsee::server::{serve_with_graceful_shutdown, stop_channel, ServerHandle, StopHandle, TowerServiceBuilder};
use jsonrpsee::server::{
serve_with_graceful_shutdown, stop_channel, ServerConfig, ServerHandle, StopHandle, TowerServiceBuilder,
};
use jsonrpsee::types::{ErrorObject, ErrorObjectOwned, Request};
use jsonrpsee::ws_client::{HeaderValue, WsClientBuilder};
use jsonrpsee::{MethodResponse, Methods};
Expand Down Expand Up @@ -174,8 +176,8 @@ async fn run_server(metrics: Metrics) -> anyhow::Result<ServerHandle> {
stop_handle: stop_handle.clone(),
metrics,
svc_builder: jsonrpsee::server::Server::builder()
.set_config(ServerConfig::builder().max_connections(33).build())
.set_http_middleware(tower::ServiceBuilder::new().layer(CorsLayer::permissive()))
.max_connections(33)
.to_service_builder(),
};

Expand Down
5 changes: 3 additions & 2 deletions examples/examples/ws_pubsub_broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use futures::StreamExt;
use jsonrpsee::core::client::{Subscription, SubscriptionClientT};
use jsonrpsee::core::server::SubscriptionMessage;
use jsonrpsee::rpc_params;
use jsonrpsee::server::{RpcModule, Server};
use jsonrpsee::server::{RpcModule, Server, ServerConfig};
use jsonrpsee::ws_client::WsClientBuilder;
use jsonrpsee::PendingSubscriptionSink;
use tokio::sync::broadcast;
Expand Down Expand Up @@ -66,7 +66,8 @@ async fn main() -> anyhow::Result<()> {

async fn run_server() -> anyhow::Result<SocketAddr> {
// let's configure the server only hold 5 messages in memory.
let server = Server::builder().set_message_buffer_capacity(5).build("127.0.0.1:0").await?;
let config = ServerConfig::builder().set_message_buffer_capacity(5).build();
let server = Server::builder().set_config(config).build("127.0.0.1:0").await?;
let (tx, _rx) = broadcast::channel::<usize>(16);

let mut module = RpcModule::new(tx.clone());
Expand Down
5 changes: 3 additions & 2 deletions examples/examples/ws_pubsub_with_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::time::Duration;
use futures::{Stream, StreamExt};
use jsonrpsee::core::client::{Subscription, SubscriptionClientT};
use jsonrpsee::core::Serialize;
use jsonrpsee::server::{RpcModule, Server, SubscriptionMessage, TrySendError};
use jsonrpsee::server::{RpcModule, Server, ServerConfig, SubscriptionMessage, TrySendError};
use jsonrpsee::ws_client::WsClientBuilder;
use jsonrpsee::{rpc_params, PendingSubscriptionSink};
use tokio::time::interval;
Expand Down Expand Up @@ -63,7 +63,8 @@ async fn main() -> anyhow::Result<()> {

async fn run_server() -> anyhow::Result<SocketAddr> {
const LETTERS: &str = "abcdefghijklmnopqrstuvxyz";
let server = Server::builder().set_message_buffer_capacity(10).build("127.0.0.1:0").await?;
let config = ServerConfig::builder().set_message_buffer_capacity(10).build();
let server = Server::builder().set_config(config).build("127.0.0.1:0").await?;
let mut module = RpcModule::new(());
module
.register_subscription(
Expand Down
4 changes: 2 additions & 2 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub use jsonrpsee_core::{id_providers::*, traits::IdProvider};
pub use jsonrpsee_types as types;
pub use middleware::rpc::RpcServiceBuilder;
pub use server::{
BatchRequestConfig, Builder as ServerBuilder, ConnectionState, PingConfig, Server, ServerConfig, TowerService,
TowerServiceBuilder,
BatchRequestConfig, Builder as ServerBuilder, ConnectionState, PingConfig, Server, ServerConfig,
ServerConfigBuilder, TowerService, TowerServiceBuilder,
};
pub use tracing;

Expand Down
Loading

0 comments on commit 1d7e0a9

Please sign in to comment.