Skip to content
Clone

feat(health): probe the RocketMQ nameserver in readyz

ZhenYi committed
parent 25f6a03 commit 5936ffb Browse files

1 file changed

+22 −4

Modified lib/export/src/health.rs View lib/export/src/health.rs
@@ -1,6 +1,8 @@
11use std::sync::Arc;
2use std::time::Duration;
23
34use actix_web::HttpResponse;
5use config::rocketmq::RocketMqConfig;
46use sea_orm::{ConnectionTrait, DbBackend, Statement};
57
68use crate::http::{Router, State, get};
@@ -10,6 +12,7 @@
1012struct HealthState {
1113 database: Option<Arc<AppDatabase>>,
1214 redis: AppRedis,
15 rocketmq: RocketMqConfig,
1316}
1417
1518async fn healthz() -> HttpResponse {
@@ -38,20 +41,35 @@
3841 redis::cmd("PING").query_async::<String>(c).await.is_ok()
3942 }
4043 };
41 if db_ok && redis_ok {
44 let rocketmq_ok = queue::probe_nameservers_with(&state.rocketmq, Duration::from_secs(1))
45 .await
46 .is_ok();
47 if db_ok && redis_ok && rocketmq_ok {
4248 HttpResponse::Ok().body("ready")
4349 } else {
4450 HttpResponse::ServiceUnavailable().body("not ready")
4551 }
4652}
4753
48pub fn router_with(database: Option<Arc<AppDatabase>>, redis: AppRedis) -> Router {
54pub fn router_with(
55 database: Option<Arc<AppDatabase>>,
56 redis: AppRedis,
57 rocketmq: RocketMqConfig,
58) -> Router {
4959 Router::<()>::new()
5060 .route("/healthz", get(healthz))
5161 .route("/readyz", get(readyz))
52 .with_state(HealthState { database, redis })
62 .with_state(HealthState {
63 database,
64 redis,
65 rocketmq,
66 })
5367}
5468
5569pub fn router(state: AppState) -> Router {
56 router_with(Some(state.database.clone()), state.redis.clone())
70 router_with(
71 Some(state.database.clone()),
72 state.redis.clone(),
73 state.config.rocketmq.clone(),
74 )
5775}