This xmlrouter servlet provides publish/subscribe messaging via simple HTTP messages.
To publish a message to a topic named 'hello-world', POST a message to '/xmlrouter/msgs/hello-world'. If the message has a content-type of 'application/x-www-form-urlencoded' (a standard browser based form) each name in the message body is turned into an XML element whose content is the value of the data in the HTTP message.
This is an example of an HTML form that will post a message to the 'hello-world' topic: (after posting something, you will need to use this page to see the results in a browser)
Here is a link to an example chat application based on this Web native publish/subscribe system. This application uses a JavaScript library to perform the publish/subscribe messaging in an asynchronous manner. Feel free to view and use this library for your own applications.
To subscribe to messages for a topic named 'hello-world', simply send a GET request to '/xmlrouter/msgs/hello-world'. The response will be an XML document with a collection of messages that have previously been posted to that topic. Here is a link to view messages for 'hello-world'.
This response contains a link (URI) to the next set of messages - essentially, the messages that have not yet arrived. Once the client has processed the retrieved messages, it would retrieve messages for the next set of messages identified by the server. The original resource for a topic is only used for the initial message retrieval - once that has occured, the client follows the 'next' link provided by the server.
A unique aspect of xmlrouter is that when a client requests messages and there are no messages available, the server will keep the connection open and wait for messages to arrive. When a message arrives at that topic, the server will then send the response to the client on the currently open connection. This results in low latency delivery of messages.