Skip to content

Commit

Permalink
Handle connection error in STOMP output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kamil-certat committed Nov 14, 2023
1 parent 717bbbf commit 1cd6eec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ CHANGELOG
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).
Expand Down
8 changes: 6 additions & 2 deletions intelmq/bots/outputs/stomp/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1cd6eec

Please sign in to comment.