@ RobotKeyword ( "Publish to MQTT Synchronously" ) @ ArgumentNames ( { "topic" , "message" , "qos=0" , "retained=false" } ) public void publishToMQTTSynchronously ( String topic , Object message , int qos , boolean retained ) throws MqttException { MqttMessage msg ; if ( message instanceof String ) { msg = new MqttMessage ( message . toString ( ) . getBytes ( ) ) ; } else { msg = new MqttMessage ( ( byte [ ] ) message ) ; } msg . setQos ( qos ) ; msg . setRetained ( retained ) ; System . out . println ( "*INFO:" + System . currentTimeMillis ( ) + "* publishing message" ) ; client . publish ( topic , msg ) ; System . out . println ( "*INFO:" + System . currentTimeMillis ( ) + "* published" ) ; }
Publish a message to a topic with specified qos and retained flag