當前位置: 首頁>>代碼示例>>Java>>正文


Java MqttMessage.setRetained方法代碼示例

本文整理匯總了Java中org.eclipse.paho.client.mqttv3.MqttMessage.setRetained方法的典型用法代碼示例。如果您正苦於以下問題:Java MqttMessage.setRetained方法的具體用法?Java MqttMessage.setRetained怎麽用?Java MqttMessage.setRetained使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.paho.client.mqttv3.MqttMessage的用法示例。


在下文中一共展示了MqttMessage.setRetained方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public synchronized boolean sendMessage(byte[] messagePayload) {
	logger.info("sending message");
	if (client != null) {
		try {
			MqttMessage message = new MqttMessage(messagePayload);
			message.setQos(qos);
			message.setRetained(false);
			client.publish(topic, message);
			return true;
		} catch (Exception e) {
			logger.error("Failed to send outbound message to topic:  " + topic + " - unexpected issue: " + new String(messagePayload));
			e.printStackTrace();
		}
	} else {
		logger.info("client is null");
	}
	return false;
}
 
開發者ID:edgexfoundry,項目名稱:export-distro,代碼行數:19,代碼來源:IotCoreMQTTSender.java

示例2: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public boolean sendMessage(byte[] messagePayload) {
	if (client != null) {
		try {
			MqttMessage message = new MqttMessage(messagePayload);
			message.setQos(qos);
			message.setRetained(false);
			client.publish(topic, message);
			return true;
		} catch (Exception e) {
			logger.error("Failed to send outbound message to topic:  " + topic + " - unexpected issue: "
					+ new String(messagePayload));
			e.printStackTrace();
		}
	}
	return false;
}
 
開發者ID:edgexfoundry,項目名稱:export-distro,代碼行數:17,代碼來源:MQTTSender.java

示例3: sendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public boolean sendMessage(byte[] messagePayload) {
  // connectClient();
  if (client != null) {
    try {
      MqttMessage message = new MqttMessage(messagePayload);
      message.setQos(OUTGOING_MQTT_QOS);
      message.setRetained(false);
      client.publish(topic, message);
      return true;
    } catch (Exception e) {
      logger.error(
          "Failed to send outbound message (unexpected issue): " + new String(messagePayload));
      logger.error(e.getLocalizedMessage());
      e.printStackTrace();
    }
  }
  return false;

}
 
開發者ID:edgexfoundry,項目名稱:device-mqtt,代碼行數:20,代碼來源:OutgoingSender.java

示例4: getMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
public MqttMessage getMessage() {
    MqttMessage message = new MqttMessage();
    message.setPayload(payload.getBytes());
    message.setQos(QoS);
    message.setRetained(isRetained());
    return message;
}
 
開發者ID:emqtt,項目名稱:EMQ-Android-Toolkit,代碼行數:8,代碼來源:Publication.java

示例5: mqttSendMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
protected void mqttSendMessage(String topic, String payload){
    byte[] encodedPayload = new byte[0];
    try {
        encodedPayload = payload.getBytes("UTF-8");
        MqttMessage message = new MqttMessage(encodedPayload);
        message.setRetained(true);
        message.setQos(1);
        client.publish(topic, message);
    } catch (UnsupportedEncodingException | MqttException e) {
        e.printStackTrace();
    }
}
 
開發者ID:chooka888,項目名稱:ConAir,代碼行數:13,代碼來源:ACController.java

示例6: valueToMessage

import org.eclipse.paho.client.mqttv3.MqttMessage; //導入方法依賴的package包/類
private MqttMessage valueToMessage ( final DataItemValue value )
{
    final MqttMessage message = new MqttMessage ();
    try
    {
        message.setPayload ( gson.toJson ( value ).getBytes ( "UTF-8" ) );
    }
    catch ( final UnsupportedEncodingException e )
    {
        logger.warn ( "could not convert value", e );
    }
    message.setRetained ( true );
    return message;
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:15,代碼來源:MqttExporter.java


注:本文中的org.eclipse.paho.client.mqttv3.MqttMessage.setRetained方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。