I know others have posted requesting a simple concrete sample application (source code) illustrating the basics of pubsub in openfire but I’ve not seen any responses/pointers. In fact, I’ve not seen any examples / pointers outside the openfire community either (that doesn’t mean an example doesn’t exist).
Was hoping that someone can provide such a pointer; I’m sure I’m not the only one that would be interested to get a response.
This is a simple example using the pubsub extensions I wrote here
Create and publish
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager = new PubSubManager(connection, “pubsub.my.openfire.server”);
OK, I will check that out. I may have missed that particular use case in my tests. I am currently on vacation though so it won’t be updated for a couple of weeks. I would suggest generating the id’s yourself in the meantime.
Thanks for the hello world example. I tried it out, I was able to create the node and publish items to the node, and the notification was able to work if the subscriber is the publisher itself.
This works because automatically the publisher automatically becomes a subscriber (I think part of the XEP-0060 specs says so).
If the subscriber is another Jabber contact, then there would need to be some extra code, I think, calling the subscribe(…) method of the Node class. Please correct me if I’m wrong.
This has now been fixed in the 0.6 version available here in the original posting. There are a couple of other changes as well since a LeafNode and CollectionNode have been introduced and a couple of methods have been removed from the PubSubManager. I will update the javadoc there as well ASAP.
Now I have a question. In your examples (and from what I’ve been able to see, in the API) you can add ItemEventListeners to single nodes. Is there a way to add a single ItemEventListener to all of the nodes that a user is subscribed to, or do we have to add them to each node separately?
The API is strictly node driven, so you have to do it by node.
Of course, you can simply register your own packet listener through the regular Smack API with an appropriate filter to accomplish the same thing. The pubsub API simply provides some conveniences beyond the more generic approach, but doesn’t stop you from using it as well.
Just follow the instructions in Smack for how to create a connection to a server from a client application. That connection is then used as documented in the example.
The example code is pretty much complete for creating a node, subscribing and registering a listener. The only part not shown is the creation of the connection, since it is standard Smack usage.
is that is the code that i added at the beginning of file PubSubManager.java
// Create a connection to the XMPP server.
XMPPConnection con = new XMPPConnection(“openfire”);
// Connect to the server
con.connect();
// Most servers require you to login before performing other tasks.
con.login("", “”);
smackx.jar for discovering node info, and accordingly then use your API to subscribe to these nodes?
i.e.
// Obtain the ServiceDiscoveryManager associated with my XMPPConnection
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Get the information of a given XMPP entity
// This example gets the information of a conference room
DiscoverInfo discoInfo = discoManager.discoverInfo("balconyscene@plays.shakespeare.lit");
// Get the discovered identities of the remote XMPP entity
Iterator it = discoInfo.getIdentities();
pubsub.my.openfire.server = pubsub. + hostname used to create connection. Pubsub is the default service name, just like conference is used to address that service. For example, there is an XMPP server at igniterealtime.org. The conference service is addressed as conference.igniterealtime.org and the pubsub service is pubsub.igniterealtime.org (I am not implying that you can access the pubsub.igniterealtime.org).
Yes. In fact, PubsubManager.discoverNodes(), **PubSubManager.getSupportedFeatures() **and Node.discoverInfo() are all convenience methods for obtaining this information.