summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Treinish <mtreinish@kortar.org>2016-09-07 23:06:08 -0400
committerMatthew Treinish <mtreinish@kortar.org>2016-10-07 15:22:46 -0400
commitd0d4f77e0db8503dff1306f0012d5a84c59de8fc (patch)
treeec1d86d100c4019d2de935709758db3487f454dc
parentf3911397912641df15b10e4c45aedf7f5b51cb45 (diff)
Add config option to set QOS of published messages
This commit adds a new config option to lpmqtt to set the QOS level for messages published to MQTT. The QOS used in MQTT is the min value between what the client and publisher use. By default lpmqtt will use a QOS level of 0, but if operating in an environment where more guarantees are needed on delivery you can set this to be higher. Change-Id: If2ce821565551fdf686e253d06356080702c05a1
Notes
Notes (review): Code-Review+2: Joshua Hesketh <joshua.hesketh@rackspace.com> Workflow+1: Matthew Treinish <mtreinish@kortar.org> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 21 Dec 2016 17:48:47 +0000 Reviewed-on: https://review.openstack.org/367061 Project: openstack-infra/lpmqtt Branch: refs/heads/master
-rw-r--r--lpmqtt/daemon.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/lpmqtt/daemon.py b/lpmqtt/daemon.py
index f009da0..ade544b 100644
--- a/lpmqtt/daemon.py
+++ b/lpmqtt/daemon.py
@@ -23,7 +23,7 @@ from lpmqtt import lp
23 23
24class PushMQTT(object): 24class PushMQTT(object):
25 def __init__(self, hostname, port=1883, client_id=None, 25 def __init__(self, hostname, port=1883, client_id=None,
26 keepalive=60, will=None, auth=None, tls=None): 26 keepalive=60, will=None, auth=None, tls=None, qos=0):
27 self.hostname = hostname 27 self.hostname = hostname
28 self.port = port 28 self.port = port
29 self.client_id = client_id 29 self.client_id = client_id
@@ -31,18 +31,19 @@ class PushMQTT(object):
31 self.will = will 31 self.will = will
32 self.auth = auth 32 self.auth = auth
33 self.tls = tls 33 self.tls = tls
34 self.qos = qos
34 35
35 def publish_single(self, topic, msg): 36 def publish_single(self, topic, msg):
36 publish.single(topic, msg, hostname=self.hostname, 37 publish.single(topic, msg, hostname=self.hostname,
37 port=self.port, client_id=self.client_id, 38 port=self.port, client_id=self.client_id,
38 keepalive=self.keepalive, will=self.will, 39 keepalive=self.keepalive, will=self.will,
39 auth=self.auth, tls=self.tls) 40 auth=self.auth, tls=self.tls, qos=self.qos)
40 41
41 def publish_multiple(self, topic, msg): 42 def publish_multiple(self, topic, msg):
42 publish.multiple(topic, msg, hostname=self.hostname, 43 publish.multiple(topic, msg, hostname=self.hostname,
43 port=self.port, client_id=self.client_id, 44 port=self.port, client_id=self.client_id,
44 keepalive=self.keepalive, will=self.will, 45 keepalive=self.keepalive, will=self.will,
45 auth=self.auth, tls=self.tls) 46 auth=self.auth, tls=self.tls, qos=self.qos)
46 47
47 48
48def process_event(event, base_topic): 49def process_event(event, base_topic):
@@ -86,12 +87,18 @@ def main():
86 if mqtt_password: 87 if mqtt_password:
87 auth['password'] = mqtt_password 88 auth['password'] = mqtt_password
88 base_topic = config.get('mqtt', 'base_topic') 89 base_topic = config.get('mqtt', 'base_topic')
90 # Max QOS
91 if config.has_option('mqtt', 'qos'):
92 mqtt_qos = config.getint('mqtt', 'qos')
93 else:
94 mqtt_qos = 0
89 95
90 mqttqueue = PushMQTT( 96 mqttqueue = PushMQTT(
91 config.get('mqtt', 'hostname'), 97 config.get('mqtt', 'hostname'),
92 port=mqtt_port, 98 port=mqtt_port,
93 keepalive=keepalive, 99 keepalive=keepalive,
94 auth=auth) 100 auth=auth,
101 qos=mqtt_qos)
95 102
96 # IMAP email settings 103 # IMAP email settings
97 imap_server = config.get('imap', 'hostname') 104 imap_server = config.get('imap', 'hostname')