Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » MQTT - persistence not working(Messages sent before subsribing topic are not received)
MQTT - persistence not working [message #1845062] Tue, 05 October 2021 10:44 Go to next message
Łukasz Drzyzga is currently offline Łukasz DrzyzgaFriend
Messages: 2
Registered: October 2021
Junior Member
Hi, I've started MQTT broker (Mosquitto) and Java application that subscribes topic "orders".

I'm using mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.mqttv5.client/1.2.5
and the client is started by code:

  public connectAndSubscribe(String topic, IMqttMessageListener messageListener) throws MqttException {
    MqttClient client = new MqttClient(mosquittoConfig.getBrokerURI(), "testClientId");
    connectClientIfNeeded(client);
    MqttSubscription subscription = new MqttSubscription(topic, mosquittoConfig.getDefaultQos());
    return client.subscribe(new MqttSubscription[]{subscription}, new IMqttMessageListener[]{messageListener});
  }

  private void connectClientIfNeeded(MqttClient client) throws MqttException {
    if (!client.isConnected()) {
      client.connect(getConnectOptions());
    }
  }

  private MqttConnectionOptions getConnectOptions() {
    MqttConnectionOptions options = new MqttConnectionOptions();
    options.setCleanStart(false);
    options.setUserName(mosquittoConfig.getUser());
    options.setPassword(mosquittoConfig.getPassword().getBytes(StandardCharsets.UTF_8));
    options.setAutomaticReconnect(true);
    options.setRequestProblemInfo(true);
    options.setRequestResponseInfo(true);
    return options;
  }


As you can see I set CleanStart to false and the clientId is constant.
But I have the following problem:

1. Mosquitto started
2. Java application started and testClientId subscribes topic "orders"
3. some client publish message "Message A" on topic "orders"
4. testClientId receive message "Message A" and execute IMqttMessageListener
5. Java application is stopped
6. some client publish message "Message B" on topic "orders"
7. Java application started and testClientId subscribes topic "orders"
8. testClientId does not receive message "Message B"

When I perform the same scenario using mosquitto it works as expected. Subscriber after reconnect receives messages sent in the meantime
mosquitto_sub -V mqttv5 -d -u <user> -P <password>-t orders -q 2 -c -i subscriberClient
Re: MQTT - persistence not working [message #1845080 is a reply to message #1845062] Wed, 06 October 2021 07:21 Go to previous message
Łukasz Drzyzga is currently offline Łukasz DrzyzgaFriend
Messages: 2
Registered: October 2021
Junior Member
I added options.setSessionExpiryInterval(EXPIRY_INTERVAL);
and it helped, mosquitto treats Java app client as a session present -> CONNACK(1, 0).
However I've another issue. Messages are sent to paho client but the messages are not processed by any registered listeners.
Sometimes while debugging I noticed created persistence files that were processed later (which is ok), but it was random, normally none of messages sent after connecting are processed by paho.
Previous Topic:MQTT C++ Client Builds Link not working
Next Topic:Java client server certificate revocation support
Goto Forum:
  


Current Time: Fri May 03 13:39:22 GMT 2024

Powered by FUDForum. Page generated in 0.04396 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top