Signed-off-by: Wu Zhende wuzhende666@163.com --- lib/mq_client.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 lib/mq_client.rb
diff --git a/lib/mq_client.rb b/lib/mq_client.rb new file mode 100755 index 0000000..412d7e1 --- /dev/null +++ b/lib/mq_client.rb @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require "bunny" + +class MQClient + def initialize(hostname = "localhost", port = "5672") + @conn = Bunny.new(hostname: hostname, port: port) + @conn.start + @channel = @conn.create_channel + end + + def queue(queue_name, opts = {}) + @channel.queue(queue_name, opts) + end + + def ack(delivery_info) + @channel.ack(delivery_info.delivery_tag) + end +end