-
Notifications
You must be signed in to change notification settings - Fork 4
Subscribe
In order to subscribe to a topic you need is a TOPIC.
Doing a GET of the TOPIC you will get a response like this:
<?xml version="1.0" encoding="utf-8"?>
<Topic xmlns="http://schemas.datacontract.org/2004/07/TellagoStudios.Hermes.RestService.Facade">
<id>4e15b4a617b6c41228ba0173</id>
<name>Weather</name>
<description />
<links>
<link uri="http://YourHermesUrl/groups/4e15b4d317b6c41228ba0174"
rel="Group"
mediaType="application/vnd.hermeshub+xml" />
<link uri="http://YourHermesUrl/topics/4e15b4a617b6c41228ba0173"
rel="Delete"
mediaType="application/vnd.hermeshub+xml" />
<link uri="http://YourHermesUrl/topics/4e15b4a617b6c41228ba0173"
rel="Update"
mediaType="application/vnd.hermeshub+xml" />
<link uri="http://YourHermesUrl/messages/topic/4e15b4a617b6c41228ba0173"
rel="Post Message"
mediaType="application/vnd.hermeshub+xml" />
<link uri="http://YourHermesUrl/feed/4e15b4a617b6c41228ba0173"
rel="Current Feed"
mediaType="application/vnd.hermeshub+xml" />
</links>
</Topic>
A subscriber must Poll the url of the relation "Current Feed".
This is a paged atom feed. The subscriber will read the logical feed, until it reachs messages with the same id from the previous read. Once it reach the previous message, the subscriber should proccess the messages backwards (remember the feed is a LIFO structure) and save the last message id for the next request.
This is an example response for a topic:
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Weather Channel</title>
<subtitle type="text"/>
<id>4e15d17b17b6c41fe4c45e77</id>
<updated>2011-07-07T15:32:18Z</updated>
<link rel="current" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b"/>
<link rel="self" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b/history/4e15d17b17b6c41fe4c45e77"/>
<link rel="prev-archive" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b/history/4e15d13a17b6c41fe4c45e6c"/>
<entry>
<id>4e15d18217b6c41fe4c45e79</id>
<title type="text">Message 4e15d18217b6c41fe4c45e79</title>
<updated>2011-07-07T15:32:18Z</updated>
<link href="http://localhost:6156/messages/4e15d18217b6c41fe4c45e79/topic/4e15d12f17b6c41fe4c45e6b"/>
<content type="text">This is the message number 12</content>
</entry>
<entry>
<id>4e15d17e17b6c41fe4c45e78</id>
<title type="text">Message 4e15d17e17b6c41fe4c45e78</title>
<updated>2011-07-07T15:32:14Z</updated>
<link href="http://localhost:6156/messages/4e15d17e17b6c41fe4c45e78/topic/4e15d12f17b6c41fe4c45e6b"/>
<content type="text">This is the message number 11</content>
</entry>
</feed>
Now, suppose the subscriber has read a previous message with id "4e15d17117b6c41fe4c45e74". Since this message is not in the "Current Feed" the subscriber will have to put these two messages in some kind of in-memory Stack, and go the previous archive.
The previous archive will be something like this:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Weather Channel</title>
<subtitle type="text"></subtitle>
<id>4e15d13a17b6c41fe4c45e6c</id>
<updated>2011-07-07T15:32:10Z</updated>
<link rel="current" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b" />
<link rel="self" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b/history/4e15d13a17b6c41fe4c45e6c" />
<link rel="next-archive" type="application/atom+xml"
href="http://localhost:6156/feed/4e15d12f17b6c41fe4c45e6b/history/4e15d17b17b6c41fe4c45e77" />
<entry>
<id>4e15d17a17b6c41fe4c45e76</id>
<title type="text">Message 4e15d17a17b6c41fe4c45e76</title>
<updated>2011-07-07T15:32:10Z</updated>
<link href="http://localhost:6156/messages/4e15d17a17b6c41fe4c45e76/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 10</content>
</entry>
<entry>
<id>4e15d17517b6c41fe4c45e75</id>
<title type="text">Message 4e15d17517b6c41fe4c45e75</title>
<updated>2011-07-07T15:32:05Z</updated>
<link href="http://localhost:6156/messages/4e15d17517b6c41fe4c45e75/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 9</content>
</entry>
<entry>
<id>4e15d17117b6c41fe4c45e74</id>
<title type="text">Message 4e15d17117b6c41fe4c45e74</title>
<updated>2011-07-07T15:32:01Z</updated>
<link href="http://localhost:6156/messages/4e15d17117b6c41fe4c45e74/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 8</content>
</entry>
<entry>
<id>4e15d16b17b6c41fe4c45e73</id>
<title type="text">Message 4e15d16b17b6c41fe4c45e73</title>
<updated>2011-07-07T15:31:55Z</updated>
<link href="http://localhost:6156/messages/4e15d16b17b6c41fe4c45e73/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 7</content>
</entry>
<entry>
<id>4e15d16717b6c41fe4c45e72</id>
<title type="text">Message 4e15d16717b6c41fe4c45e72</title>
<updated>2011-07-07T15:31:51Z</updated>
<link href="http://localhost:6156/messages/4e15d16717b6c41fe4c45e72/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 6</content>
</entry>
<entry>
<id>4e15d16217b6c41fe4c45e71</id>
<title type="text">Message 4e15d16217b6c41fe4c45e71</title>
<updated>2011-07-07T15:31:46Z</updated>
<link href="http://localhost:6156/messages/4e15d16217b6c41fe4c45e71/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 5</content>
</entry>
<entry>
<id>4e15d15d17b6c41fe4c45e70</id>
<title type="text">Message 4e15d15d17b6c41fe4c45e70</title>
<updated>2011-07-07T15:31:41Z</updated>
<link href="http://localhost:6156/messages/4e15d15d17b6c41fe4c45e70/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 4</content>
</entry>
<entry>
<id>4e15d15817b6c41fe4c45e6f</id>
<title type="text">Message 4e15d15817b6c41fe4c45e6f</title>
<updated>2011-07-07T15:31:36Z</updated>
<link href="http://localhost:6156/messages/4e15d15817b6c41fe4c45e6f/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 3</content>
</entry>
<entry>
<id>4e15d15317b6c41fe4c45e6e</id>
<title type="text">Message 4e15d15317b6c41fe4c45e6e</title>
<updated>2011-07-07T15:31:31Z</updated>
<link href="http://localhost:6156/messages/4e15d15317b6c41fe4c45e6e/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 2</content>
</entry>
<entry>
<id>4e15d14d17b6c41fe4c45e6d</id>
<title type="text">Message 4e15d14d17b6c41fe4c45e6d</title>
<updated>2011-07-07T15:31:25Z</updated>
<link href="http://localhost:6156/messages/4e15d14d17b6c41fe4c45e6d/topic/4e15d12f17b6c41fe4c45e6b" />
<content type="text">This is the message number 1</content>
</entry>
</feed>
The subscriber will read the message number 10 and 9, and then will reach the 8 which is already read from the previous poll operation. Now the subscriber have to "yield" the messages from the top of the stack to the client API.
There is an example of this algorithm here.