From c1445b60bca62f4ddb8a7d3cd5431da19267b1d7 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Nov 17 2021 17:33:10 +0000 Subject: Start setting expiry on sent protonmsg messages Fixes #3120. --- diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index 1ec332f..7fbb31e 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -203,12 +203,14 @@ The following fields are understood: before timing out The ``[message]`` section sets parameters for how messages are formed. -Currently only one field is understood: * ``extra_limit`` -- the maximum allowed size for ``build.extra`` fields that - appear in messages. If the ``build.extra`` field is longer (in terms of + appear in messages. If the ``build.extra`` field is longer (in terms of json-encoded length), then it will be omitted. The default value is ``0`` which means no limit. +* ``ttl`` -- the time in seconds before the broker should consider sent + messages to have expired. The broker may drop messages that have not been + delivered before the ``ttl`` is up. The default value is ``86400`` (24 hours). The ``[queue]`` section controls how (or if) the plugin will use the database to queue messages when they cannot be immediately sent. diff --git a/plugins/hub/protonmsg.conf b/plugins/hub/protonmsg.conf index 33e98b7..a945d7b 100644 --- a/plugins/hub/protonmsg.conf +++ b/plugins/hub/protonmsg.conf @@ -11,6 +11,8 @@ send_timeout = 60 # if field is longer (json.dumps), ignore it # default value is 0 - unlimited size extra_limit = 0 +# Time after which the broker should expire messages +ttl = 86400 [queue] # enable persistent database queue diff --git a/plugins/hub/protonmsg.py b/plugins/hub/protonmsg.py index 3fc62b0..6c7663c 100644 --- a/plugins/hub/protonmsg.py +++ b/plugins/hub/protonmsg.py @@ -75,6 +75,9 @@ class TimeoutHandler(MessagingHandler): self.send_msgs(event) def send_msgs(self, event): + ttl = 86400 # a 24 hour default for message expiry + if self.conf.has_option('message', 'ttl'): + ttl = self.conf.getint('message', 'ttl') prefix = self.conf.get('broker', 'topic_prefix') for msg in self.msgs: address = 'topic://' + prefix + '.' + msg['address'] @@ -86,6 +89,7 @@ class TimeoutHandler(MessagingHandler): self.log.debug('created new sender for %s', address) self.senders[address] = sender pmsg = Message(properties=msg['props'], body=msg['body']) + pmsg.ttl = ttl delivery = sender.send(pmsg) self.log.debug('sent message: %s', msg['props']) self.pending[delivery] = msg