====== HTTP ↔ XMPP - PubSub gateway ======
~~DRAFT~~
[[http://www.xmpp.org/extensions/xep-0060.html|XEP-0060]] defines a Publish-Subscribe extension to the [[http://xmpp.org|XMPP]] protocol. [[http://ralphm.net/|Ralph Meijer]] has written a gateway to interface to the XMPP world via HTTP RPC: [[http://idavoll.ik.nu/|Idavoll]] implements a Jabber publish-subscribe service component, as defined in XEP-0060, aiming to be fully compliant and mostly complete.
I use idavoll for the [[dokupubsub|DokuWiki pubsub plugin]] and started this wiki page to collect resources during development.
===== Background Information =====
The basic concept works as follows:
- An entity publishes information to a node at a publish-subscribe service.
- The pubsub service pushes a notification to all entities that are authorized to learn about the published information.
Here: the //entities// are web-servers running a CMS (wiki, repositories etc); the //node//s are XML data-containers.
The idavoll gateway accepts [[wp>ATOM_(standard)|Atom]]-Entries (and Atom-Feeds) as payload((Atom is a common denominator for the XMPP/XMLstream and HTTP/XHTML)). The //content// inside the Atom can be any [XML-encoded] data.
Each node has a unique identifier - the **NodeID** or xmpp-uri - which is generated when publishing an item for the first time.
A document made up of multiple entries can be represented as a //feed// aka. //collection//. XEP-0060 defines a **collection node** as «A type of node that contains nodes and/or other collections but no published items. Collections make it possible to represent hierarchial node structures».
Luckily idavoll hides the gory details, and offers a neat way to "tunnel and distribute" HTTP requests. It runs along with a underlying jabber daemon next to the webserver(s).
$data['callback']='';
$data['uri']='';
|
^ Returns | //no-content// - HTTP status-code 204 on success.|
^ Description | subscribe to updates of an xmpp-node.\\ The gateway will send HTTP-POST requests to the specified callback-url. see //notification handling// below.|
==== unsubscribe ====
^ Name | ''/unsubscribe'' |
^ Parameters | //none// |
^ Data | JSON encoded array of content-type ''application/json'' $data['callback']='';
$data['uri']='';
|
^ Returns | //no-content// - HTTP status-code 204 on success.|
^ Description | unsubscribe from receiving notifications.\\ use the same parameters as for the //subscribe// request.|
==== delete ====
^ Name | ''/delete'' |
^ Parameters | ''uri'' (string) xmpp-uri |
^ Data | //none// \\ content-type must be set to''application/atom+xml;type=entry;charset=utf-8'' |
^ Returns | JSON encoded array of known publications.|
^ Description | same as publishing empty content. |
==== items ====
^ Name | ''/items'' |
^ Parameters | ''uri'' (string) xmpp-uri of feed |
^ Data | //none// |
^ Returns | JSON encoded array of entries in the feed.|
^ Description | query entries in a collection.|
==== list ====
^ Name | ''/list'' - **HTTP-GET** |
^ Parameters | //none// |
^ Data | //none// |
^ Returns | JSON encoded array of known publications.|
^ Description | handy to test, debug or just see what's going on..|
===== notification handling =====
After successful subscription and for each published update to an xmpp node, idavoll notifies the subscriber via HTTP POST.
Here's an example in PHP to catch those and dump them. Idavoll ignores any replied data,
===== further notes =====
Idavoll includes support to discover and subscribe to //feeds//. It automatically creates a collection node for a given RSS or Atom and starts polling the feed, publishes changes. read more about this feature: http://idavoll.ik.nu/wiki/FeedAggregation
What's missing?\\ idavoll, wokkel, twisted and jabberd provide a method plus infrastructure for communication and put some constraints on the language. You're to supply the user-interface ;)
Publishing is easy. Managing subscriptions is not.. - the latter includes both user/admin wishes to subscribe to content as well as handle data-updates, format-translations etc. YMMV.
A first CMS using idavoll for sharing is [[http://anymeta.nl|anyMeta]]. Being a well administrated commercial CMS, anyMeta makes use of //authoritative source// and //read-only// mirrors which are subscribed to the authoritative source. In the spirit of [[http://data-portability.org|data-portability]] these authoritative sources may move and hop to a different server; reversing the role of publisher and subscriber or even be removed. subscribers may also choose if to keep or delete content if the source gets unavailable...
Updates to a node are //atomic transaction// in the XMPP world. A later publication to a node invalidates the previous one. The jabber server responsible for the node is the authoritative source for the content. This mechanism does allow to build a //distributed lock// or coherent cache model: fi. one could publish //drafts-documents// to mark the beginning of a edit-cycle that ends in a re-publication. If an entity receives a //Draft// it can perform a context appropriate action like locking the page, merging content or reporting a conflict to the user either local or remote (send back a newer //Draft//).
Furthermore subscribers can implement automatic-actions such as retire subscriptions if the authoritative source gets unavailable or aggregate additional information that is not part of the publication itself. - Subscribers can also choose to act differently depending on content-signature or authentication credentials (eg oAuth over XMPP)..