- Notifications
You must be signed in to change notification settings - Fork41
🍃spring-rs is a application framework written in rust inspired by java's spring-boot
License
spring-rs/spring-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
spring-rs is an application framework that emphasizes convention over configuration, inspired by Java's SpringBoot.spring-rs provides an easily extensible plug-in system for integrating excellent projects in the Rust community, such as axum, sqlx, sea-orm, etc.
Compared with SpringBoot in java, spring-rs has higher performance and lower memory usage, allowing you to completely get rid of the bloated JVM and travel light.
- ⚡️ High performance: Benefiting from the awesome rust language,spring-rs has the ultimate performance comparable to C/C++
- 🛡️ High security: Compared to C/C++, the Rust language used byspring-rs provides memory safety and thread safety.
- 🔨 Lightweight: The core code of spring-rs does not exceed 5,000 lines, and the binary size of the release version packaged in rust is also small.
- 🔧 Easy to use:spring-rs provides a clear and concise API and optional Procedural Macros to simplify development.
- 🔌 Highly extensible:spring-rs uses a highly extensible plug-in model, and users can customize plug-ins to extend program capabilities.
- ⚙️ Highly configurable:spring-rs uses toml to configure applications and plug-ins to improve application flexibility.
web
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]asyncfnmain(){App::new().add_plugin(SqlxPlugin).add_plugin(WebPlugin).run().await}#[get("/")]asyncfnhello_world() ->implIntoResponse{"hello world"}#[route("/hello/{name}", method ="GET", method ="POST")]asyncfnhello(Path(name):Path<String>) ->implIntoResponse{format!("hello {name}")}#[get("/version")]asyncfnsqlx_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)}
job
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]asyncfnmain(){App::new().add_plugin(JobPlugin).add_plugin(SqlxPlugin).run().await; tokio::time::sleep(Duration::from_secs(100)).await;}#[cron("1/10 * * * * *")]asyncfncron_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)]asyncfnfix_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)]asyncfnfix_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
: Based onaxum
spring-sqlx
: Integrated withsqlx
spring-postgres
: Integrated withrust-postgres
spring-sea-orm
: Integrated withsea-orm
spring-redis
: Integrated withredis
spring-mail
: Integrated withlettre
spring-job
: Integrated withtokio-cron-scheduler
spring-stream
: Integratesea-streamer
to implement message processing such as redis-stream and kafkaspring-opentelemetry
: Integrate withopentelemetry
to implement full observability of logging, metrics, tracingspring-grpc
: Integratetonic
to implement gRPC calls
We also welcome community experts to contribute their own plugins.Contributing →
Click here to view common problems encountered when usingspring-rs
Help →
About
🍃spring-rs is a application framework written in rust inspired by java's spring-boot
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.