After the service restarted, the queue information is not lost.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/lifecycle.cr | 2 +- src/lib/mq.cr | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/lib/lifecycle.cr b/src/lib/lifecycle.cr index 16830d0..3dab6e8 100644 --- a/src/lib/lifecycle.cr +++ b/src/lib/lifecycle.cr @@ -311,7 +311,7 @@ class Lifecycle return if Time.local < deadline
mq_queue = get_machine_reboot_queue(testbox) - @mq.pushlish_confirm(mq_queue, machine.to_json) + @mq.pushlish_confirm(mq_queue, machine.to_json, durable: true)
machine["state"] = "rebooting_queue" machine["time"] = Time.local.to_s("%Y-%m-%dT%H:%M:%S+0800") diff --git a/src/lib/mq.cr b/src/lib/mq.cr index 011d732..87c67e9 100644 --- a/src/lib/mq.cr +++ b/src/lib/mq.cr @@ -3,6 +3,7 @@
require "singleton" require "amqp-client" +require "amq-protocol"
class MQClient getter ch : AMQP::Client::Channel @@ -19,14 +20,22 @@ class MQClient Singleton::Of(self).instance end
- def pushlish_confirm(queue, msg) - q = @ch.queue(queue) - q.publish_confirm msg + def pushlish_confirm(queue, msg, passive = false, durable = false, exclusive = false, auto_delete = false) + q = @ch.queue(queue, passive, durable, exclusive, auto_delete) + if durable + q.publish_confirm(msg, props: AMQ::Protocol::Properties.new(delivery_mode: 2)) + else + q.publish_confirm msg + end end
- def pushlish(queue, msg) - q = @ch.queue(queue) - q.publish msg + def pushlish(queue, msg, passive = false, durable = false, exclusive = false, auto_delete = false) + q = @ch.queue(queue, passive, durable, exclusive, auto_delete) + if durable + q.publish(msg, props: AMQ::Protocol::Properties.new(delivery_mode: 2)) + else + q.publish(msg) + end end
def get(queue)