rocketmq-rust icon indicating copy to clipboard operation
rocketmq-rust copied to clipboard

[Refactor♻️] Use native async fn for the broker's DeferredReplayRead trait

Open mxsm opened this issue 1 week ago • 1 comments

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

  1. Add #[trait_variant::make(Send)] to DeferredReplayRead, keep the Sync supertrait, and declare async fn read_message(...) -> Option<GetMessageResult>. Elide the shared lifetime and remove the unused std::future::Future import.
  2. In the implementation for MS: BrokerReadWriteStore, forward the same arguments to get_message and await its result.
  3. Convert ScriptedReplayStore and TaggedReplayStore in replay_tests to 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

mxsm avatar Nov 23 '26 03:11 mxsm

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.

lipeh1 avatar Nov 23 '26 06:11 lipeh1