多服务
2025年8月17日小于 1 分钟hyperlanewebrustconfigmulti-server
提示
hyperlane
框架支持多服务模式,仅需创建多个 server
实例并进行监听即可
多服务
提示
启动多个服务,监听多个端口
let app1 = spawn(async move {
let config: ServerConfig = ServerConfig::new().await;
config.host("0.0.0.0").await;
config.port(80).await;
let server: Server = Server::from(config).await;
server.route("/", |ctx: Context| async move {
let _ = ctx.send_status_body(200, "hello world").await;
}).await;
let _ = server.listen().await;
});
let app2 = spawn(async move {
let config: ServerConfig = ServerConfig::new().await;
config.host("0.0.0.0").await;
config.port(81).await;
let server: Server = Server::from(config).await;
server.route("/", |ctx: Context| async move {
let _ = ctx.send_status_body(200, "hello world").await;
}).await;
let _ = server.listen().await;
});
let _ = tokio::join!(app1, app2);