Eclipse Paho MQTT generates a lot of folders containing a .lck file
Asked Answered
F

2

5

In a Java project I'm using the Eclipse Paho MQTT library. Into the project root I have a lot of folders like c32adeb3-f556-4563-afbe-8417b1de74ea-tcp1270018883 cointaining a .lck file.

Can I delete all these folders? When can I delete them?

Floria answered 4/3, 2021 at 17:1 Comment(0)
L
4

The reason is simple, this is because when you don't pass the persistence type explicitly MqttClient will use the MqttDefaultFilePersistence by default:

public MqttClient(String serverURI, String clientId) throws MqttException {
    this(serverURI, clientId, new MqttDefaultFilePersistence());
}

You can ignore .lck files by setting persistence type explicitly to null or an instance of MemoryPersistence class:

client = new MqttClient("tcp://ip_of_server:1883", client_id, null);

or

client = new MqttClient("tcp://ip_of_server:1883", client_id, new MemoryPersistence());

Lacour answered 4/4, 2022 at 14:13 Comment(0)
E
2

These are the folders for handling message persistence for QOS 1 or 2 messages.

If you are seeing multiple directories being created that means you are generating fresh client ids for each connection which implies that you are not worried about messages high QOS delivery across restarts. Then I suggest switch to using the Memory backed persistence store rather than the filesystem based version.

http://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/persist/MemoryPersistence.html

Ediva answered 4/3, 2021 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.