Skip to content

Commit

Permalink
[ISSUE #140]🎨Add Broker bootstrap (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm authored Feb 3, 2024
1 parent b59fdca commit b47a106
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions rocketmq-broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ description.workspace = true
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" }
rocketmq-store = { version = "0.2.0", path = "../rocketmq-store" }

anyhow.workspace = true
env_logger.workspace = true
Expand Down
15 changes: 14 additions & 1 deletion rocketmq-broker/src/bin/broker_bootstrap_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@
*/

use clap::Parser;
use rocketmq_broker::command::Args;
use rocketmq_broker::{broker_controller::BrokerController, command::Args};
use rocketmq_common::common::broker::broker_config::BrokerConfig;
use rocketmq_rust::rocketmq;

#[rocketmq::main]
async fn main() -> anyhow::Result<()> {
rocketmq_common::log::init_logger();
let controller = create_broker_controller()?;
start_broker_controller(controller)?;
Ok(())
}

fn create_broker_controller() -> anyhow::Result<BrokerController> {
let _args = Args::parse();
Ok(BrokerController::new(BrokerConfig::default()))
}

fn start_broker_controller(broker_controller: BrokerController) -> anyhow::Result<()> {
let mut broker_controller = broker_controller;
broker_controller.start();
Ok(())
}
31 changes: 31 additions & 0 deletions rocketmq-broker/src/broker_controller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 rocketmq_common::common::broker::broker_config::BrokerConfig;

pub struct BrokerController {
pub(crate) broker_config: BrokerConfig,
}

impl BrokerController {
pub fn new(broker_config: BrokerConfig) -> Self {
Self { broker_config }
}
}

impl BrokerController {
pub fn start(&mut self) {}
}
2 changes: 2 additions & 0 deletions rocketmq-broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
* limitations under the License.
*/

#![allow(dead_code)]
pub mod broker_controller;
pub mod command;
1 change: 1 addition & 0 deletions rocketmq-common/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod mq_version;
pub mod namesrv;
mod sys_flag;
pub use crate::common::sys_flag::topic_sys_flag as TopicSysFlag;
pub mod broker;
pub mod message;
pub mod topic;

Expand Down
1 change: 1 addition & 0 deletions rocketmq-common/src/common/broker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod broker_config;
89 changes: 89 additions & 0 deletions rocketmq-common/src/common/broker/broker_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 crate::common::mix_all;

#[derive(Debug, Default)]
pub struct BrokerIdentity {
broker_name: String,
broker_cluster_name: String,
broker_id: u64,
is_broker_container: bool,
is_in_broker_container: bool,
}

impl BrokerIdentity {
fn new() -> Self {
let broker_name = default_broker_name();
let broker_cluster_name = String::from("DefaultCluster");
let broker_id = mix_all::MASTER_ID;
let is_broker_container = false;

BrokerIdentity {
broker_name,
broker_cluster_name,
broker_id,
is_broker_container,
is_in_broker_container: false,
}
}

fn new_with_container(is_broker_container: bool) -> Self {
let mut identity = BrokerIdentity::new();
identity.is_broker_container = is_broker_container;
identity
}

fn new_with_params(broker_cluster_name: String, broker_name: String, broker_id: u64) -> Self {
BrokerIdentity {
broker_name,
broker_cluster_name,
broker_id,
is_broker_container: false,
is_in_broker_container: false,
}
}

fn new_with_container_params(
broker_cluster_name: String,
broker_name: String,
broker_id: u64,
is_in_broker_container: bool,
) -> Self {
BrokerIdentity {
broker_name,
broker_cluster_name,
broker_id,
is_broker_container: true,
is_in_broker_container,
}
}
}

fn default_broker_name() -> String {
// Implement logic to obtain default broker name
// For example, use local hostname
// ...

// Placeholder value for demonstration
String::from("DefaultBrokerName")
}

#[derive(Debug, Default)]
pub struct BrokerConfig {
pub broker_identity: BrokerIdentity,
}

0 comments on commit b47a106

Please sign in to comment.