Skip to content

Commit

Permalink
Reuse timestamp in rabbit_message_interceptor
Browse files Browse the repository at this point in the history
 ## What?
`mc:init()` already sets mc annotation `rts` (received timestamp).
This commit reuses this timestamp in `rabbit_message_interceptor`.

 ## Why?
`os:system_time/1` can jump forward or backward between invocations.
Using two different timestamps for the same meaning, the time the message
was received by RabbitMQ, can be misleading.
  • Loading branch information
ansd committed Aug 6, 2024
1 parent cb8fa6d commit f447986
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions deps/rabbit/src/rabbit_message_interceptor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ intercept(Msg, set_header_routing_node, Overwrite) ->
Node = atom_to_binary(node()),
set_annotation(Msg, ?HEADER_ROUTING_NODE, Node, Overwrite);
intercept(Msg0, set_header_timestamp, Overwrite) ->
Millis = os:system_time(millisecond),
Msg = set_annotation(Msg0, ?HEADER_TIMESTAMP, Millis, Overwrite),
set_timestamp(Msg, Millis, Overwrite).
Ts = mc:get_annotation(?ANN_RECEIVED_AT_TIMESTAMP, Msg0),
Msg = set_annotation(Msg0, ?HEADER_TIMESTAMP, Ts, Overwrite),
set_timestamp(Msg, Ts, Overwrite).

-spec set_annotation(mc:state(), mc:ann_key(), mc:ann_value(), boolean()) -> mc:state().
set_annotation(Msg, Key, Value, Overwrite) ->
Expand Down

0 comments on commit f447986

Please sign in to comment.