Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion streamz/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,12 +896,15 @@ class from_mqtt(from_q):
:param client_kwargs:
Passed to the client's ``connect()`` method
"""
def __init__(self, host, port, topic, keepalive=60 , client_kwargs=None, **kwargs):
def __init__(self, host, port, topic, keepalive=60 , client_kwargs=None,
user=None, pw=None, **kwargs):
self.host = host
self.port = port
self.keepalive = keepalive
self.topic = topic
self.client_kwargs = client_kwargs
self.user = user
self.pw = pw
super().__init__(q=queue.Queue(), **kwargs)

def _on_connect(self, client, userdata, flags, rc):
Expand All @@ -913,6 +916,8 @@ def _on_message(self, client, userdata, msg):
async def run(self):
import paho.mqtt.client as mqtt
client = mqtt.Client()
if self.user:
client.username_pw_set(self.user, self.pw)
client.on_connect = self._on_connect
client.on_message = self._on_message
client.connect(self.host, self.port, self.keepalive, **(self.client_kwargs or {}))
Expand Down