Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit 10bab72

Browse files
author
Philip Yu
committed
feat(message): add option deliver_at and deliver_after
1 parent 343b1b8 commit 10bab72

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

ext/bindings/message.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Message::Message(const std::string& data, Rice::Object arg = Rice::Object()) {
3434
mb.setPartitionKey(Rice::Object(it->value).to_s().str());
3535
} else if (key == "ordering_key") {
3636
mb.setOrderingKey(Rice::Object(it->value).to_s().str());
37+
} else if (key == "deliver_after") {
38+
mb.setDeliverAfter(std::chrono::milliseconds(from_ruby<uint64_t>(Rice::Object(it->value))));
39+
} else if (key == "deliver_at") {
40+
mb.setDeliverAt(from_ruby<uint64_t>(Rice::Object(it->value)));
3741
} else {
3842
throw Rice::Exception(rb_eArgError, "Unknown keyword argument: %s", key.c_str());
3943
}

spec/pulsar/message_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@
3131
end
3232
end
3333

34+
describe "deliver_at" do
35+
it "does not raise error" do
36+
expect do
37+
described_class.new("payload", deliver_at: 1000)
38+
end.not_to raise_error
39+
end
40+
end
41+
42+
describe "deliver_after" do
43+
it "does not raise error" do
44+
expect do
45+
described_class.new("payload", deliver_after: (Time.now.to_i + 5) * 1000)
46+
end.not_to raise_error
47+
end
48+
end
49+
3450
describe "properties" do
3551
it "takes properties" do
3652
m = described_class.new("payload", properties: {"a" => "1", "b" => "2"})
@@ -129,6 +145,18 @@
129145
described_class.new("payload", properties: [])
130146
end.to raise_exception(TypeError)
131147
end
148+
149+
it "rejects deliver at that is not an integer" do
150+
expect do
151+
described_class.new("payload", deliver_at: "x")
152+
end.to raise_exception(TypeError)
153+
end
154+
155+
it "rejects deliver after that is not an integer" do
156+
expect do
157+
described_class.new("payload", deliver_after: "x")
158+
end.to raise_exception(TypeError)
159+
end
132160
end
133161
end
134162
end

0 commit comments

Comments
 (0)