spring rs
0.3.0
영어 | 中文
Spring-Rs 는 Java의 SpringBoot에서 영감을 얻은 구성에 대한 컨벤션을 강조하는 응용 프로그램 프레임 워크입니다. Spring-Rs는 Axum, SQLX, Sea-Orm 등과 같은 Rust 커뮤니티에서 우수한 프로젝트를 통합하기위한 쉽게 확장 가능한 플러그인 시스템을 제공합니다.
Java의 SpringBoot와 비교할 때 Spring-Rs는 성능이 높고 메모리 사용량이 낮아서 부풀린 JVM 및 Travel Light를 완전히 제거 할 수 있습니다.
편물
use spring :: { auto_config , App } ;
use spring_sqlx :: {
sqlx :: { self , Row } ,
ConnectPool , SqlxPlugin
} ;
use spring_web :: { get , route } ;
use spring_web :: {
error :: Result , extractor :: { Path , Component } , handler :: TypeRouter , axum :: response :: IntoResponse , Router ,
WebConfigurator , WebPlugin ,
} ;
use anyhow :: Context ;
# [ auto_config ( WebConfigurator ) ]
# [ tokio :: main ]
async fn main ( ) {
App :: new ( )
. add_plugin ( SqlxPlugin )
. add_plugin ( WebPlugin )
. run ( )
. await
}
# [ get ( "/" ) ]
async fn hello_world ( ) -> impl IntoResponse {
"hello world"
}
# [ route ( "/hello/:name" , method = "GET" , method = "POST" ) ]
async fn hello ( Path ( name ) : Path < String > ) -> impl IntoResponse {
format ! ( "hello {name}" )
}
# [ get ( "/version" ) ]
async fn sqlx_request_handler ( Component ( pool ) : Component < ConnectPool > ) -> Result < String > {
let version = sqlx :: query ( "select version() as version" )
. fetch_one ( & pool )
. await
. context ( "sqlx query failed" ) ?
. get ( "version" ) ;
Ok ( version )
}직업
use anyhow :: Context ;
use spring :: { auto_config , App } ;
use spring_job :: { cron , fix_delay , fix_rate } ;
use spring_job :: { extractor :: Component , JobConfigurator , JobPlugin } ;
use spring_sqlx :: {
sqlx :: { self , Row } ,
ConnectPool , SqlxPlugin ,
} ;
use std :: time :: { Duration , SystemTime } ;
# [ auto_config ( JobConfigurator ) ]
# [ tokio :: main ]
async fn main ( ) {
App :: new ( )
. add_plugin ( JobPlugin )
. add_plugin ( SqlxPlugin )
. run ( )
. await ;
tokio :: time :: sleep ( Duration :: from_secs ( 100 ) ) . await ;
}
# [ cron ( "1/10 * * * * *" ) ]
async fn cron_job ( Component ( db ) : Component < ConnectPool > ) {
let time : String = sqlx :: query ( "select TO_CHAR(now(),'YYYY-MM-DD HH24:MI:SS') as time" )
. fetch_one ( & db )
. await
. context ( "query failed" )
. unwrap ( )
. get ( "time" ) ;
println ! ( "cron scheduled: {:?}" , time )
}
# [ fix_delay ( 5 ) ]
async fn fix_delay_job ( ) {
let now = SystemTime :: now ( ) ;
let datetime : sqlx :: types :: chrono :: DateTime < sqlx :: types :: chrono :: Local > = now . into ( ) ;
let formatted_time = datetime . format ( "%Y-%m-%d %H:%M:%S" ) ;
println ! ( "fix delay scheduled: {}" , formatted_time )
}
# [ fix_rate ( 5 ) ]
async fn fix_rate_job ( ) {
tokio :: time :: sleep ( Duration :: from_secs ( 10 ) ) . await ;
let now = SystemTime :: now ( ) ;
let datetime : sqlx :: types :: chrono :: DateTime < sqlx :: types :: chrono :: Local > = now . into ( ) ;
let formatted_time = datetime . format ( "%Y-%m-%d %H:%M:%S" ) ;
println ! ( "fix rate scheduled: {}" , formatted_time )
} spring-web : axum 기반으로합니다 spring-sqlx : sqlx 와 통합 spring-postgres : rust-postgres 와 통합 spring-sea-orm : sea-orm 와 통합 spring-redis : redis 와 통합 spring-mail : lettre 와 통합 spring-job : tokio-cron-scheduler 와 통합 spring-stream : sea-streamer 통합하여 Redis-Stream 및 Kafka와 같은 메시지 처리를 구현합니다. spring-opentelemetry : opentelemetry 와 통합하여 로깅, 메트릭, 추적의 전체 관찰 가능성을 구현합니다. spring-tarpc : RPC 통화를 구현하기 위해 tarpc 통합합니다 spring-sqlx-migration-pluginspring-opendal더 >>
또한 커뮤니티 전문가가 자신의 플러그인을 제공하도록 환영합니다. 기고 →
spring-rs 도움말을 사용할 때 발생하는 일반적인 문제를 보려면 여기를 클릭하십시오 →