[Why]
If the rabbitmq service is disconnected,
monitoring service can't work.
When the rabbitmq service restored,need to restart monitoring service.
So need to let monitoring service automatic reconnection
Signed-off-by: Wu Zhende <wuzhende666(a)163.com>
---
src/monitoring/amqp.cr | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/monitoring/amqp.cr b/src/monitoring/amqp.cr
index 1a97dc4..b0341ce 100644
--- a/src/monitoring/amqp.cr
+++ b/src/monitoring/amqp.cr
@@ -16,18 +16,29 @@ class MessageQueueClient
conn.try &.close
end
+ private def filter_msg(conn, filter, exchange_name, queue_name)
+ conn.channel do |channel|
+ queue = channel.queue(queue_name)
+ queue.bind(exchange_name, "")
+ queue.subscribe(tag: queue_name, block: true) do |msg|
+ begin
+ filter.filter_msg(msg.body_io)
+ rescue e
+ puts "filter message error: #{e}"
+ end
+ end
+ end
+ end
+
def monitoring_message_queue(filter : Filter, exchange_name : String, queue_name : String)
- start do |conn|
- conn.channel do |channel|
- queue = channel.queue(queue_name)
- queue.bind(exchange_name, "")
- queue.subscribe(tag: queue_name, block: true) do |msg|
- begin
- filter.filter_msg(msg.body_io)
- rescue e
- puts "filter message error: #{e}"
- end
+ loop do
+ begin
+ start do |conn|
+ filter_msg(conn, filter, exchange_name, queue_name)
end
+ rescue e
+ puts "monitoring_message_queue error: #{e}"
+ sleep 5
end
end
end
--
2.23.0