Subject: Publish-Subscribe (JEP-0060) code for simple use cases
For a project I'm currently on I fiddled around with the Publish-Subscribe extension for Jabber (http://www.jabber.org/jeps/jep-0060.html). I wrote some code to cover the most basic use cases:
The code is a bit rough around the edges as I was just prototyping but it does the job. There's a factory which even hides the complexity of putting DOM elements together. The following code demonstrates how to create, subscribe and publish to a node whereas the xmppClientConnection variable is a placeholder for an XmppClientConnection instance:
If anybody is interested in the code just drop me a message!
By the way, I used the Wildfire Jabber Server and a snapshot of Idavoll2 as JEP-0060 component.
- subscribing to an existing node
- creating a new node on the server
- publishing something to a node
- requesting information about a node
- requesting the default node configuration
- requesting information about all affiliations of the user
- requesting all items of a node
The code is a bit rough around the edges as I was just prototyping but it does the job. There's a factory which even hides the complexity of putting DOM elements together. The following code demonstrates how to create, subscribe and publish to a node whereas the xmppClientConnection variable is a placeholder for an XmppClientConnection instance:
- xmppClientConnection.Send(PubsubElementFactory psubElementFactory = new PubsubElementFactory("pubsub.jabber.org", xmppClientConnection.MyJID));
- string testNodeName = "TestNode";
- xmppClientConnection.Send(psubElementFactory.CreateNode(testNodeName));
- xmppClientConnection.Send(psubElementFactory.Subscribe(testNodeName));
- Element payload = new Element("myPubSubSuperTag");
- xmppClientConnection.Send(psubElementFactory.Publish(testNodeName, payload));
If anybody is interested in the code just drop me a message!
By the way, I used the Wildfire Jabber Server and a snapshot of Idavoll2 as JEP-0060 component.
This post was edited on 2006-04-09, 00:12 by Alex.