Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Question about message persistence

Hi all,

I was looking into how a QoS level of 1 (messages sent at least once) was implemented in the Eclipse Paho Mqtt Java Client library, and noticed that this level is only ensured if the client is connected. In case the app tries to publish messages while it isn't connected, the messages just get discarded instead of 'queued' for re-sending (in the form of the .msg files) once the client re-connects. Is this how it actually works?

The particular code snipped I was looking at was this in ClientComms.java:

public void sendNoWait(MqttWireMessage message, MqttToken token) throws MqttException {
final String methodName = "sendNoWait";
if (isConnected() ||    // <- this check would fail (as would the others below), so it would never go to internalSend, which ultimately leads to saving the message on disk. But instead just throws the Exception.
(!isConnected() && message instanceof MqttConnect) ||
(isDisconnecting() && message instanceof MqttDisconnect)) {
this.internalSend(message, token);
} else {
//@TRACE 208=failed: not connected
log.fine(className, methodName, "208");
throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED);
}
}

If this is the case, is it not a violation of the QoS level of 1? Would I be able to request this particular feature?

In addition, is there any sample code that you have which would do what I described above? Or any advice on how to implement this particular functionality ourselves?

Thank you so much for your help,
Sincerely,
Herman

Back to the top