PIOT-GDA-10-002: Update MqttClientConnector to send received messages to an IDataMessageListener instance #92
Labels
exercise
New feature to implement as an exercise
Milestone
Description
MqttClientConnector
to subscribe to the CDA's topics related toSensorData
messages,SystemPerformanceData
messages, andActuatorData
response messages.messageArrived()
callback implementation or create a separate callback class for each topic that implements theIMqttMessageListener
interface.Review the README
Estimated effort may vary greatly
Actions
IMPORTANT NOTE 1: You will likely need to use
MqttAsyncClient
in place ofMqttClient
depending on the integration use cases you implement. Why? You can encounter a deadlock condition using the synchronousMqttClient
if, for example, you're subscribed to topic A, receive a message from the broker on topic A, and then attempt to re-publish that message on topic B. Simply change theMqttClient
references (declaration and new instance) toMqttAsyncClient
, and re-run your tests from Lab Module 07 and here in this Lab Module to verify the change executes as expected.IMPORTANT NOTE 2: If you have not yet run PIOT-INT-10-001, be sure to do so BEFORE switching the
MqttClientConnector
code from the synchronousMqttClient
to the asynchronousMqttAsyncClient
. It will not success if using the asyncMqttAsyncClient
.Using the Asynchronous MQTT Client (
MqttAsyncClient
)connectClient()
method accordingly.Update the subscriber functionality
IDataMessageListener
for callbacks, or another callback method contained withinMqttClientConnector
. There are two ways to support this, as follows:connectComplete()
callback once theconnectClient()
is called and the connection to the broker succeeds, ensuring the necessary topic subscriptions are called after a successful broker connection.DeviceDataManager
(after invoking theconnectClient()
method on your MQTT client instance withinDeviceDataManager
, for instance, during thestartManager()
call), you should remove that logic before moving forward.mqttClient.messageArrived()
callback already in place, and either parse the content within the method before sending to the appropriateIDataMessageListener
callback instanceIMqttMessageListener
interface. You can use inner classes or create separate external classes.connectComplete()
callback by subscribing to the given topics using either Option 1 or Option 2 above.Subscribe - Option 1
connectComplete()
callback, add the generic subscriptions:Subscribe - Option 2
SensorData
messages,SystemPerformanceData
messages, andActuatorData
response messages - you'll need one inner class for EACH).ActuatorData
response messages, which can be embedded at the end ofMqttClientConnector
:IMqttMessageListener
to handle bothSensorData
andSystemPerformanceData
messages! Use the template above forActuatorResponseMessageListener
to assist with this. Here are two shell examples - you will need to implement these on your own:connectComplete()
callback, add the inner class callback and subscription:Update DeviceDataManager
DeviceDataManager
, comment out the subscribe calls in thestartManager()
method.startManager()
method may include additional calls not depicted below.The text was updated successfully, but these errors were encountered: