Skip to content

Commit 2aeac2e

Browse files
authored
Allow any timestamp in AMQP messages (#1705)
Don't parse the timestamp property as part of the publish path. Users might use invalid timestamps, and we don't want to reject those messages. Fixes #1684 Closes #1685
1 parent f89ec08 commit 2aeac2e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

spec/server_spec.cr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,19 @@ describe LavinMQ::Server do
873873
end
874874
end
875875

876+
it "allows any Int64 message timestamp" do
877+
with_amqp_server do |s|
878+
with_channel(s) do |ch|
879+
q = ch.queue
880+
props = AMQP::Client::Properties.new(timestamp: Int64::MAX)
881+
q.publish "m1", props: props
882+
msg = q.get(no_ack: true).not_nil!
883+
msg.body_io.to_s.should eq "m1"
884+
msg.properties.timestamp_raw.should eq Int64::MAX
885+
end
886+
end
887+
end
888+
876889
it "sets correct message timestamp" do
877890
LavinMQ::Config.instance.set_timestamp = true
878891
with_amqp_server do |s|

src/lavinmq/amqp/channel.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module LavinMQ
221221
@publish_count.add(1, :relaxed)
222222
@client.vhost.event_tick(EventType::ClientPublish)
223223
props = @next_msg_props.not_nil!
224-
props.timestamp = RoughTime.utc if props.timestamp.nil? && Config.instance.set_timestamp?
224+
props.timestamp = RoughTime.utc if props.timestamp_raw.nil? && Config.instance.set_timestamp?
225225
msg = Message.new(RoughTime.unix_ms,
226226
@next_publish_exchange_name.not_nil!,
227227
@next_publish_routing_key.not_nil!,

0 commit comments

Comments
 (0)