MQTT Subscription ends when Microflow ends

0
I’m trying to import data via MQTT and implemented the MQTT-Connector. My current Problem is that i can’t receive the data yet. I tryed a few different microflows and realized that when i put the subscription and the publish action in the same microflow it works. But if i split them up and call them afterwards the subscription doesn’t show anything.   The following doesn’t give me a message when i call the first microflow and then the second (in “Subscribe to MQTT” i’m calling a microflow to display the payload):   But this somehow works and gives me back the message from the published data in the microflow   So from my understanding the Subscription is just active while the microflow is active… But i don’t understand how i can keep it active due to looping while being able to apply other actions. Grateful for any help   Tim  
asked
1 answers
1

Good news, no need to loop it to keep it active. I recently implemented this module and I can give you a brief breakdown of how I set it up. Also good news; you don’t need the Publish flow unless you’re trying to update Mqtt information, if you’re only ‘listening’ you can just use the Subscribe action.

Firstly, I see you’re making a ConnectionDetail object, but only adding two attributes. Check the MqttConnector module, specifically the ‘ConnectToBroker’. If you examine the java action(and supporting java code) you’ll see it needs a enum for the auth type at the very least, potentially more, as I didn’t try it while lacking attributes and used basic auth.

Secondly, you want to subscribe after you’ve connected; essentially Connect → Subscribe → Await messages. The connection step is basically to verify that your ConnectionDetail object is correctly set up.

Try using the SampleonMessage flow from the Mqtt module for the Subscribe, it’ll spit your message results into the log, or you could create a different one to store it in an object, but you’ll need some import mapping to do so.

Lastly, you’ll need to trigger your Mqtt server to send a message before you can catch it; this will vary depending on your setup. In addition, you could use a tool like MqttFx client to verify your server is sending messages, then you know where the issue is (server vs Mendix)

Final tip: you’ll need an after start-up flow to re-subscribe between shut downs if you want the subscriptions to be active on start up, otherwise they need to be re-established manually.

answered