Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Hi guys

Create a Java Class that implements MqttCallback

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

for example MyCallback. MyCallback has to implement some methods one of them is deliveryComplete(...). You should code your logic to store the latest delivered message there.

Then, suppose you have a MqttClient "myClient". You tell this client to use your callback using its setCallback() method. Do the following:

MyCallback myCallback = new MyCallback();
MqttClient myClient = new MqttClient(YourServerURI, YourClientId);
myClient.setCallback(myCallback);
[...]

Then

- if myClient is disconnected from the broker, the myCallback.connectionLost(...) method is called.
- If you publish a message through myClient, the myCallback.deliveryComplete(...) method is called on success.
- If you subscribe a topic through myClient, the myCallback.messageReceived(...) method is called when a message is published to this topic.

This is very basic. I hope it helps. 

Regards.








2015-05-12 12:42 GMT+02:00 neuber sousa <neuberfran@xxxxxxxxx>:


But, perhaps, the easy way is to implement the deliveryComplete(...) method of MqttCallback to store the delivered message"

How to do this above?
Please, I'm a newer in mqtt and paho

Em 12/05/2015 06:56, "Manuel Domínguez Dorado" <manolodd@xxxxxxxxx> escreveu:
However, Neuber, you could implement your own MqttClientPersistence to do whatever you want to do or, simpler, inherit from MqttDefaultFilePersistence maintaining everything intact except the required modifications to "store" the latest message sent into another place.

But, perhaps, the easy way is to implement the deliveryComplete(...) method of MqttCallback to store the delivered message.

Regards.

2015-05-12 11:48 GMT+02:00 Ian Craggs <icraggs@xxxxxxxxxxxxxxxxxxxxxxx>:
Hi,

it's a bit difficult to understand your question, so I'll take a guess.

The data persistence is only used for storing intermediate state of messages, not a record of previous publications.  Once a message has been successfully sent or received, it is no longer in the persistent store.

Ian


On 05/11/2015 11:51 PM, neuber sousa wrote:
http://blog.csdn.net/kuailebeihun_/article/details/25245023

i do this tutorial in eclipse kepler and everything is ok. 

Now I'm trying put         String tmpDir = System.getProperty("java.io.tmpdir");
and       final  MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersiste(tmpDir); in this project
and in the server project (i.e.: the server project publish msg(s) to topic "xxx/yyy", with qos = 2)


My questions is: In the first time when I start a java project (in eclipse) , I need read latest post of the topic "xxx/yyy" relative to dataStore file persist.

How to do this ??




_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs                          
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev



--
---
Manuel Domínguez Dorado
ingeniero ARROBA ManoloDominguez PUNTO com
http://www.ManoloDominguez.com

_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev



--
---
Manuel Domínguez Dorado
ingeniero ARROBA ManoloDominguez PUNTO com
http://www.ManoloDominguez.com

Back to the top