Question

I am having a problem with an application using Smack 3.1 and a server running openfire. Upon starting the application, it will read the last message on the node. This doesn't work since the messages are parsed, processed and placed into a db. Besides sending a message creation time in the payload, is there any way to stop this duplication? (Actually if there is anyway to signal that a message has been "consumed" would be fantastic)

Was it helpful?

Solution

If you are referring to pubsub then you can either configure the node so that it does not persist items with persist_items and max_items.

If you have no control over the node creation then what you can do is check for the delay namespace (jabber:x:delay and/or urn:xmpp:delay) in the packet

public void processPacket(Packet pkt) {
   DelayInformation delay = (DelayInformation)pkg.getExtension("x", "jabber:x:delay");
   if (delay != null)
      return; //Discard this packet
   delay = (DelayInformation)pkg.getExtension("x", "urn:xmpp:delay");
   if (delay != null)
      return; //Discard this as well
   //Otherwise this is a good packet
   ...
}

You can also make some decision by examining the DelayInformation object as to how long, reason, etc.

If it is PEP then you will always get the last item published and I think there is no way of determining if it was delayed viz. there is no delay info in the packet.

You need to either get nightly builds or build your own for pubsub support. I don't think the current version Smack 3.1.0 supoorts pubsub.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top