From a81572abab18aa3bcc5666ea177bb12917845b23 Mon Sep 17 00:00:00 2001 From: Kamil Mankowski Date: Tue, 14 Nov 2023 10:09:35 +0100 Subject: [PATCH] Handle connection error in STOMP output Sometimes the output bot gots disconnected, and stays so until restart or reload. This change adds a try to reconnect. It intentionally doesn't hide the error, but let's IntelMQ handle message retry. --- CHANGELOG.md | 2 ++ intelmq/bots/outputs/stomp/output.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aae7fd66..92eebfa5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,8 @@ of necessary file(s)). - Add `stomp.py` version check (raise `MissingDependencyError` if not `>=4.1.12`). - Minor fixes/improvements and some refactoring (see also above: *Core*...). +- `intelmq.bots.outputs.stomp.output` (PR#2423 by Kamil Mankowski): + - Try to reconnect on `NotConnectedException`. ### Documentation - Add a readthedocs configuration file to fix the build fail (PR#2403 by Sebastian Wagner). diff --git a/intelmq/bots/outputs/stomp/output.py b/intelmq/bots/outputs/stomp/output.py index 50c9a1d5f..6beb0fa56 100644 --- a/intelmq/bots/outputs/stomp/output.py +++ b/intelmq/bots/outputs/stomp/output.py @@ -76,8 +76,12 @@ def process(self): body = self.export_event(event) - self._conn.send(body=body, - destination=self.exchange) + try: + self._conn.send(body=body, destination=self.exchange) + except stomp.exception.NotConnectedException: + self.logger.warning("Detected connection error, trying to reestablish it.") + self.connect() + raise # Fallback to default retry self.acknowledge_message() @classmethod