leizhiyuan opened a new pull request, #1477:
URL: https://github.com/apache/rocketmq-clients/pull/1477

   ### Which Issue(s) This PR Fixes
   
   Fixes #1476
   
   ### Brief Description
   
   The Rust client wrote **milliseconds since the start of the current month** 
into the time field of the V1 message id (the legacy 4.x semantics), while 
Java/Go/Python/C#/C++/Node.js write **the lower 4 bytes of the seconds since 
2021-01-01 00:00:00 UTC**. As a result the broker / dashboard decodes Rust 
message ids to a future time (e.g. `0156F7E71C361B21BC168b2de000000132` → 
2032-12-26).
   
   This PR aligns `rust/src/model/message_id.rs` with the Java `MessageIdCodec`:
   
   - Time field: seconds since 2021-01-01 UTC, lower 4 bytes, big endian. The 
wall clock is read once and then advanced with the monotonic clock (`Instant`), 
like Java's `nanoTime`. This also removes the month-start bookkeeping and its 
`i32` overflow / 30-day refresh issues.
   - The whole id is upper case hex (the suffix used to be lower case).
   - The sequence starts from 0 and wraps around, like Java.
   
   The version byte and the MAC / PID prefix are unchanged. Message ids already 
generated by older clients are not affected.
   
   ### How Did You Test This Change?
   
   Added unit tests in `rust/src/model/message_id.rs` (replacing the previously 
`#[ignore]`d one):
   
   - `regression_legacy_message_id_decoded_as_2032`: the reported legacy id 
decodes to 2032-12-26; the fixed generator produces `...0AFDE06C00000132` for 
the same send time, which decodes back to 2026-11-05 09:03:40 UTC.
   - `time_field_decodes_to_send_time_on_any_day_of_month`: the epoch, start / 
end of month, around the old "looks right" boundary on the 3rd, the old `i32` 
overflow point on the 25th, March 1-2, a leap day and 2050 all decode back to 
the send time.
   - `time_field_advances_with_monotonic_clock`, 
`global_generator_uses_current_time_and_upper_case`, 
`encode_matches_java_v1_layout` (the example in the Java doc), 
`encode_keeps_lower_4_bytes_of_seconds`, `sequence_starts_from_zero_and_wraps`.
   
   Locally:
   
   - `cargo test --lib`: 181 passed
   - `cargo fmt --check`, `cargo clippy --all-features -- -D warnings`, `cargo 
doc --no-deps --all-features`: passed
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to