[Refactor♻️] Use native async fn for the broker's DeferredReplayRead trait
Target Code
The change fits in rocketmq-broker/src/broker_runtime/deferred_producer/workers.rs. Start at the private DeferredReplayRead trait and its read_message method. Open the trait and production implementation.
Problems
The broker reads stored messages before waking deferred Pull, POP, and notification requests. The trait and its three implementations repeat the same lifetime and impl Future signature. Replay workers need the returned future to be Send. The broker already expresses this with a native async method on QueryMessageStore. See the existing pattern.
Proposed Changes
- Add
#[trait_variant::make(Send)]toDeferredReplayRead, keep theSyncsupertrait, and declareasync fn read_message(...) -> Option<GetMessageResult>. Elide the shared lifetime and remove the unusedstd::future::Futureimport. - In the implementation for
MS: BrokerReadWriteStore, forward the same arguments toget_messageand await its result. - Convert
ScriptedReplayStoreandTaggedReplayStoreinreplay_teststo native async methods. Return the queued response or tag-filtered result directly.
The existing tests should still show that an unavailable read requests a retry, an exact POP replay checks the requested offset and batch span, and each waiter uses its own tag filter.
Run both commands from the repository root.
cargo fmt -p rocketmq-broker -- --check
cargo test -p rocketmq-broker --lib deferred_producer::workers::replay_tests
I'd like to work on this issue. I'll convert DeferredReplayRead::read_message and its implementations to native async fn, keep the Send bound, and run the replay tests.