Skip to content

Commit

Permalink
[ISSUE #141]💥Add Broker command line parse (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm authored Feb 2, 2024
1 parent 36a4033 commit b59fdca
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 13 deletions.
32 changes: 32 additions & 0 deletions rocketmq-broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,35 @@ description.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocketmq-rust = { version = "0.2.0", path = "../rocketmq" }
rocketmq-common = { version = "0.2.0", path = "../rocketmq-common" }
rocketmq-remoting = { version = "0.2.0", path = "../rocketmq-remoting" }

anyhow.workspace = true
env_logger.workspace = true

tokio.workspace = true
tokio-util.workspace = true
tokio-stream.workspace = true

tracing.workspace = true
tracing-subscriber.workspace = true

#json spupport
serde.workspace = true
serde_json.workspace = true

futures-core = "0.3.0"
futures-sink = "0.3.0"
futures-io = { version = "0.3.0"}
futures-util = { version = "0.3.0"}
futures = "0.3.29"
bytes = "1.5.0"
config.workspace = true
parking_lot.workspace = true

clap = { version = "4.2.7", features = ["derive"] }

[[bin]]
name = "rocketmq-broker-rust"
path = "src/bin/broker_bootstrap_server.rs"
27 changes: 27 additions & 0 deletions rocketmq-broker/src/bin/broker_bootstrap_server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use clap::Parser;
use rocketmq_broker::command::Args;
use rocketmq_rust::rocketmq;

#[rocketmq::main]
async fn main() -> anyhow::Result<()> {
rocketmq_common::log::init_logger();
let _args = Args::parse();
Ok(())
}
49 changes: 49 additions & 0 deletions rocketmq-broker/src/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use std::path::PathBuf;

use clap::Parser;

#[derive(Parser, Debug)]
#[command(
author = "mxsm",
version = "0.2.0",
about = "RocketMQ Broker Server(Rust)"
)]
pub struct Args {
/// Broker config properties file
#[arg(short, long, value_name = "FILE", default_missing_value = "None")]
config_file: Option<PathBuf>,

/// Print important config item
#[arg(short = 'm', long, required = false)]
print_important_config: bool,

/// Name server address list, eg: '192.168.0.1:9876;192.168.0.2:9876'
#[arg(
short,
long,
value_name = "IP",
default_value = "127.0.0.1:9876",
required = false
)]
namesrv_addr: String,

///Print all config item
#[arg(short, long, required = false)]
print_config_item: bool,
}
30 changes: 17 additions & 13 deletions rocketmq-broker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
pub mod command;

0 comments on commit b59fdca

Please sign in to comment.