Skip to content

Commit e03b951

Browse files
authored
[ISSUE #224]🎨Using cfg to solve the problem that the MessageStore trait cannot be converted to an object (#225)
1 parent 9f20367 commit e03b951

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

‎rocketmq-broker/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ description.workspace = true
1212

1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

15+
[features]
16+
default = ["local_file_store"]
17+
local_file_store = ["rocketmq-store/local_file_store"]
18+
1519
[dependencies]
1620
rocketmq-rust = { version = "0.2.0", path = "../rocketmq" }
1721
rocketmq-common = { version = "0.2.0", path = "../rocketmq-common" }
1822
rocketmq-remoting = { version = "0.2.0", path = "../rocketmq-remoting" }
19-
rocketmq-store = { version = "0.2.0", path = "../rocketmq-store" }
23+
rocketmq-store = { version = "0.2.0", path = "../rocketmq-store", default-features = true}
2024

2125
anyhow.workspace = true
2226
env_logger.workspace = true

‎rocketmq-broker/src/broker_controller.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ pub struct BrokerController {
101101
pub(crate) cold_data_pull_request_hold_service: ColdDataPullRequestHoldService,
102102
pub(crate) cold_data_cg_ctr_service: ColdDataCgCtrService,
103103
pub(crate) broker_outer_api: BrokerOuterAPI,
104-
pub(crate) message_store: Option<Box<dyn MessageStore>>,
104+
#[cfg(feature = "local_file_store")]
105+
pub(crate) message_store: Option<LocalFileMessageStore>,
105106
pub(crate) timer_message_store: Option<TimerMessageStore>,
106107
pub(crate) replicas_manager: Option<ReplicasManager>,
107108
pub(crate) broker_server: Option<RocketmqDefaultServer>,
@@ -160,7 +161,7 @@ impl BrokerController {
160161

161162
impl BrokerController {
162163
pub async fn start(&mut self) {
163-
if self.message_store.is_some() {
164+
if self.message_store.as_mut().is_some() {
164165
let _ = self.message_store.as_mut().unwrap().start();
165166
}
166167

@@ -206,7 +207,7 @@ impl BrokerController {
206207
pub fn initialize_message_store(&mut self) -> bool {
207208
if self.store_config.store_type == StoreType::LocalFile {
208209
info!("Use local file as message store");
209-
self.message_store = Some(Box::<LocalFileMessageStore>::default());
210+
self.message_store = Some(LocalFileMessageStore::default());
210211
} else if self.store_config.store_type == StoreType::RocksDB {
211212
info!("Use RocksDB as message store");
212213
} else {

0 commit comments

Comments
 (0)