Assembly: mindtouch.dream
Class: MindTouch.Dream.EventsService
SID: http://services.mindtouch.com/dream/...2007/03/events
Overview
The Events
service provides simple publication/subscription API for messages. An application publishes a message by doing a POST:events/ request on the service. The service will queue the message, give it a unique eventid, and notify any active listeners about its arrival.
Listeners can be notified via two different means: either they subscribe to the event service with a POST:subscribe/ request, or they poll with a GET:events/ request. The latter can be set to wait until a message arrives, avoiding repetitive polling operations when no messages are present.
| Verb:Suffix |
Description |
| GET:events |
Get list of all messages |
| GET: |
Get list of all messages |
| POST:events |
Add a message |
| POST: |
Add a message |
| POST:subscribe |
Add a subscriber |
| POST:unsubscribe |
Remove a subscriber |
Data Types
Config
<config>
<!-- default duration in seconds to keep a message for -->
<default-ttl>30</default-ttl>
<!-- default duration in seconds to keep a GET:events/ operation alive when no messages are present -->
<default-wait>10</default-wait>
</config>
Message
A message can be any valid XML document. Every message is tagged with a sequential eventid and eventdate (Beryil and later). If the following document is posted to the Events service.
<ticker>
<symbol>GE</symbol>
<price>32.82</price>
</ticker>
It will be sent to listeners as:
<ticker eventid="42" eventdate="2006-05-22T01:16:03.0716064Z">
<symbol>GE</symbol>
<price>32.82</price>
</ticker>
MessageList
<list maxeventid="42" eventdate="2006-05-22T01:16:03.0716064Z">
<ticker eventid="42">
<symbol>GE</symbol>
<price>32.82</price>
</ticker>
</list>
Subscription
<subscription>
<uri>http://localhost/myService/myListener</node>
</subscription>
Features
GET:events/
Get a list of all events.
Query Parameters
| Name |
Type |
Default
|
Description |
| after |
int |
0 |
Only send events that occurred after this eventid |
| wait |
int? |
variable |
Duration in seconds to block the request until until a message arrives. Default behavior does not block. Value can be omitted, defaulting to service specific duration. |
Response
| Status |
Response Body |
Description |
| 200 |
MessageList |
A list of messages matching the request. |
Version History
Aqua: feature added
GET:/
Get a list of all events.
Query Parameters
| Name |
Type |
Default
|
Description |
| after |
int |
0 |
Only send events that occurred after this eventid |
| wait |
int? |
variable |
Duration
in seconds to block the request until until a message arrives. Default
behavior does not block. Value can be omitted, defaulting to service
specific duration. |
Response
| Status |
Response Body |
Description |
| 200 |
MessageList |
A list of messages matching the request. |
Version History
Beryl: feature added
POST:events/
Add a message to the list of messages. If any listeners are waiting or if subscribers are present, notify them about the new message.
Query Parameters
| Name |
Type |
Defaut
|
Description |
| ttl |
double |
variable |
Time-to-live in seconds for the posted message. If not specified, service default will be used.
|
Request Body
The request body must contain a valid XML document.
Response
| Status |
Response Body |
Description |
| 200 |
--- |
No result returned. |
Version History
Beryl: ttl is now a double representing seconds (in Aqua, it was an integer representing days)
Aqua: feature added
POST:/
Add a message to the list of messages. If any listeners are waiting
or if subscribers are present, notify them about the new message.
Query Parameters
| Name |
Type |
Defaut
|
Description |
| ttl |
double |
variable |
Time-to-live in seconds for the posted message. If not specified, service default will be used. |
Request Body
The request body must contain a valid XML document.
Response
| Status |
Response Body |
Description |
| 200 |
--- |
No result returned. |
Version History
Aqua: feature added
POST:subscribe/
Adds a subscriber to the Events service. By default, a new subscriber only receives messages that are sent after the subscription has been established. However, by providing the after query parameter, this behavior can be changed to return all message in the Event service that occurred after the specified eventid, but before the subscription was established.
Query Parameters
| Name |
Type |
Defaut
|
Description |
| after |
int |
MaxInt |
Only send events that occurred after this eventid. |
Request Body
A Subscription XML document specifying the uri of the subscriber.
Response
| Status |
Response Body |
Description |
| 200 |
--- |
No result returned. |
| 400 |
XHTML |
The reason why the request failed. |
Version History
Aqua: feature added
POST:unsubscribe/
Removes a subscriber from the Events service. This operation succeeds regardless if the specified subscription has established a subscription or not.
Request Body
A Subscription XML document specifying the uri of the subscriber.
Response
| Status |
Response Body |
Description |
| 200 |
--- |
No result returned. |
Version History
Aqua: feature added
Future Extensions
- Allow Subsription to contain an xpath expression so that only matching messages are sent to the subscriber.