use of org.eclipse.paho.client.mqttv3.MqttPersistenceException in project ha-bridge by bwssytems.
the class MQTTHandler method publishMessage.
public void publishMessage(String topic, String content) {
MqttMessage message = new MqttMessage(StringEscapeUtils.unescapeJava(content).getBytes());
message.setQos(qos);
try {
myClient.publish(topic, message);
} catch (MqttPersistenceException e) {
log.error("Could not publish to MQTT client for name: " + myConfig.getName() + " and ip: " + myConfig.getIp() + " with message: " + e.getMessage());
} catch (MqttException e) {
log.error("Could not publish to MQTT client for name: " + myConfig.getName() + " and ip: " + myConfig.getIp() + " with message: " + e.getMessage());
}
}
use of org.eclipse.paho.client.mqttv3.MqttPersistenceException in project aware-client by denzilferreira.
the class Mqtt method publish.
/**
* Publish message to topic
*
* @param topicName
* @param messageText
*/
public static boolean publish(String topicName, String messageText) {
if (MQTT_CLIENT != null && MQTT_CLIENT.isConnected()) {
try {
MqttMessage message = new MqttMessage();
message.setPayload(messageText.getBytes());
message.setQos(Integer.parseInt(MQTT_QoS));
message.setRetained(true);
MQTT_CLIENT.publish(topicName, message);
} catch (MqttPersistenceException e) {
if (Aware.DEBUG)
Log.e(TAG, e.getMessage());
return false;
} catch (MqttException e) {
if (Aware.DEBUG)
Log.e(TAG, e.getMessage());
return false;
}
}
return true;
}
use of org.eclipse.paho.client.mqttv3.MqttPersistenceException in project nifi by apache.
the class MqttTestClient method publish.
@Override
public void publish(String topic, byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException {
MqttMessage message = new MqttMessage(payload);
message.setQos(qos);
message.setRetained(retained);
switch(type) {
case Publisher:
publishedMessage = new MQTTQueueMessage(topic, message);
break;
case Subscriber:
try {
mqttCallback.messageArrived(topic, message);
} catch (Exception e) {
throw new MqttException(e);
}
break;
}
}
Aggregations