当前位置: 首页>>代码示例>>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;未经允许,请勿转载。