use clap::Parser;
use rocketmq_admin_core::client_adapter::services::consumer::ConsumerService;
use rocketmq_admin_core::client_adapter::services::consumer::StartMonitoringRequest;
use crate::commands::CommandExecute;
#[derive(Debug, Clone, Parser)]
pub struct StartMonitoringSubCommand {
#[arg(
short = 'n',
long = "namesrvAddr",
required = false,
help = "Name server address list, eg: '192.168.0.1:9876;192.168.0.2:9876'"
)]
namesrv_addr: Option<String>,
}
impl StartMonitoringSubCommand {
fn request(&self) -> StartMonitoringRequest {
StartMonitoringRequest::new(self.namesrv_addr.clone())
}
}
impl CommandExecute for StartMonitoringSubCommand {
async fn execute(
&self,
credentials: Option<rocketmq_admin_core::core::security::AdminCredentials>,
client_runtime: std::sync::Arc<rocketmq_admin_core::client_adapter::ClientRuntime>,
) -> rocketmq_error::Result<()> {
let result = ConsumerService::start_monitoring_by_request_with_credentials(
self.request(),
credentials,
client_runtime.clone(),
)
.await?;
for event in result.events {
println!("{event:?}");
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn start_monitoring_sub_command_builds_request() {
let command = StartMonitoringSubCommand::try_parse_from(["startMonitoring", "-n", " 127.0.0.1:9876 "]).unwrap();
let request = command.request();
assert_eq!(request.namesrv_addr(), Some("127.0.0.1:9876"));
}
}