protected void publish() throws MqttException, IOException {
  String payload="Message from blocking MQTTv3 Java client sample";
  String clientId="SampleJavaV3_pubMIDP";
  String pubTopic="Sample/Java/v3";
  String url="tcp://" + broker + ":"+ port;
  if (SSL) {
    url="ssl://" + broker + ":"+ sslport;
  }
  pubClinet=new MqttClient(url,clientId);
  pubClinet.setCallback(this);
  pubClinet.connect();
  MqttMessage message=new MqttMessage(payload.getBytes());
  message.setQos(qos);
  pubClinet.publish(pubTopic,message);
  pubClinet.disconnect();
  pubClinet=null;
}

protected void publish ( ) throws MqttException , IOException { String payload = "Message from blocking MQTTv3 Java client sample" ; String clientId = "SampleJavaV3_pubMIDP" ; String pubTopic = "Sample/Java/v3" ; String url = "tcp://" + broker + ":" + port ; if ( SSL ) { url = "ssl://" + broker + ":" + sslport ; } pubClinet = new MqttClient ( url , clientId ) ; pubClinet . setCallback ( this ) ; pubClinet . connect ( ) ; MqttMessage message = new MqttMessage ( payload . getBytes ( ) ) ; message . setQos ( qos ) ; pubClinet . publish ( pubTopic , message ) ; pubClinet . disconnect ( ) ; pubClinet = null ; }
publish / send a message to an mqtt server
