powered by Jive Software

Su smack - using addPacketListener to receive pubsub events


I’m writing a pub sub subscription client and have chosen su smack as a helper library.

There is very little sample code and apparently no guide or manual, so I have done my best with the following, which unfortunately does not work (listener never gets called, though I see valid pubsub events in the received message debug stream). I have been able to subscribe to the topic, etc; it is only event reception that is the problem.

Has anyone got this working? Or should I be using a different approach?

PacketFilter packetFilter = XMPPUtils.createPubSubFilter();
               PacketListener packetListener = XMPPUtils.createEventPacketListener(
                         new PubSubEventListener() {
                              public void onDelete(DeleteElement deletedElt)
                                        throws Exception {
                                   System.out.println("*** d ***");
                              }                               public void onPublish(ItemElement publishedElt)
                                        throws Exception {
                                   System.out.println("*** item ***");
                              }                               public void onPurge(PurgeElement purgedElt)
                                        throws Exception {
                                   System.out.println("*** p ***");
                              }                               public void onRetract(RetractElement retractedElt)
                                        throws Exception {
                                   System.out.println("*** r ***");
               );                c.addPacketListener(packetListener, packetFilter);

Try using the latest version of Smack from trunk. It contains an API for using pubsub.

IMHO it is much easier to use than su-smack, and its usage is is documented along with other Smack extensions.

Also, why is this under Spark Support instead of Smack Support? Are you adding the functionality to Spark?

Oops, my mistake. Any further correspondence I’ll make sure to put under Smack.

Thanks for the pointer re: Smack update.

I have done more investigation and I’m not yet convinced it’s a problem with su smack (although that is not very easy to use and as I mentioned, essentially you’re on your own re: docs); I am getting unexpected results from Smack methods like Packet.getExtension(). Perhaps the newer code works better.

I agree with you about ease of use.

That is why I wrote the Smack extension to support pubsub . This old thread gives some history, and here is the documentation.