Java Code Examples for org.eclipse.paho.client.mqttv3.MqttMessage#isRetained()

The following examples show how to use org.eclipse.paho.client.mqttv3.MqttMessage#isRetained() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MqttExporter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param itemId
 * @param message
 *            from MQTT topic
 * @return converted value
 * @throws MqttException
 */
private DataItemValue messageToValue ( final String itemId, final MqttMessage message ) throws MqttException
{
    final DataItemValue div;
    try
    {
        div = gson.fromJson ( new String ( message.getPayload (), "UTF-8" ), DataItemValue.class );
        if ( message.isRetained () || message.isDuplicate () )
        {
            logger.info ( "message is retained/duplicate, will not write" );
            return null;
        }
        return div;
    }
    catch ( JsonSyntaxException | UnsupportedEncodingException e1 )
    {
        logger.warn ( "could not parse message {}", message );
        return null;
    }
}
 
Example 2
Source File: MQTTQueueMessage.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public MQTTQueueMessage(String topic, MqttMessage message) {
    this.topic = topic;
    payload = message.getPayload();
    qos = message.getQos();
    retained = message.isRetained();
    duplicate = message.isDuplicate();
}
 
Example 3
Source File: EmqMessage.java    From EMQ-Android-Toolkit with Apache License 2.0 5 votes vote down vote up
public EmqMessage(String topic, MqttMessage mqttMessage) {
    this.topic = topic;
    this.mqttMessage = mqttMessage;
    this.updateTime = StringUtil.formatNow();

    if (mqttMessage != null) {
        this.dup = mqttMessage.isDuplicate();
        this.payload = new String(mqttMessage.getPayload());
        this.qos = mqttMessage.getQos();
        this.messageId = mqttMessage.getId();
        this.retained = mqttMessage.isRetained();
    }


}
 
Example 4
Source File: Message.java    From mqtt-jmeter with Apache License 2.0 5 votes vote down vote up
public Message(MqttMessage mqttMessage) {
    this.payload = mqttMessage.getPayload();
    this.qos = mqttMessage.getQos();
    this.retained = mqttMessage.isRetained();
    this.dup = mqttMessage.isDuplicate();
    this.currentTimestamp = System.currentTimeMillis();
}
 
Example 5
Source File: MQTTQueueMessage.java    From nifi with Apache License 2.0 5 votes vote down vote up
public MQTTQueueMessage(String topic, MqttMessage message) {
    this.topic = topic;
    payload = message.getPayload();
    qos = message.getQos();
    retained = message.isRetained();
    duplicate = message.isDuplicate();
}
 
Example 6
Source File: DatabaseMessageStore.java    From Sparkplug with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Store an MQTT message
 * 
 * @param clientHandle
 *            identifier for the client storing the message
 * @param topic
 *            The topic on which the message was published
 * @param message
 *            the arrived MQTT message
 * @return an identifier for the message, so that it can be removed when appropriate
 */
@Override
public String storeArrived(String clientHandle, String topic,
		MqttMessage message) {
	
	db = mqttDb.getWritableDatabase();
	
	traceHandler.traceDebug(TAG, "storeArrived{" + clientHandle + "}, {"
			+ message.toString() + "}");

	byte[] payload = message.getPayload();
	int qos = message.getQos();
	boolean retained = message.isRetained();
	boolean duplicate = message.isDuplicate();

	ContentValues values = new ContentValues();
	String id = java.util.UUID.randomUUID().toString();
	values.put(MqttServiceConstants.MESSAGE_ID, id);
	values.put(MqttServiceConstants.CLIENT_HANDLE, clientHandle);
	values.put(MqttServiceConstants.DESTINATION_NAME, topic);
	values.put(MqttServiceConstants.PAYLOAD, payload);
	values.put(MqttServiceConstants.QOS, qos);
	values.put(MqttServiceConstants.RETAINED, retained);
	values.put(MqttServiceConstants.DUPLICATE, duplicate);
	values.put(MTIMESTAMP, System.currentTimeMillis());
	try {
		db.insertOrThrow(ARRIVED_MESSAGE_TABLE_NAME, null, values);
	} catch (SQLException e) {
		traceHandler.traceException(TAG, "onUpgrade", e);
		throw e;
	}
	int count = getArrivedRowCount(clientHandle);
	traceHandler
			.traceDebug(
					TAG,
					"storeArrived: inserted message with id of {"
							+ id
							+ "} - Number of messages in database for this clientHandle = "
							+ count);
	return id;
}
 
Example 7
Source File: MqttConfig.java    From quarks with Apache License 2.0 4 votes vote down vote up
/**
 * Get a Last Will and Testament message's "retained" setting.
 * @return the value.
 */
public boolean getWillRetained() {
    MqttMessage msg = options.getWillMessage();
    return msg==null ? false : msg.isRetained();
}