Created
May 8, 2014 10:15
-
-
Save gregoryyoung/cc3f9e5582f3bf00119b to your computer and use it in GitHub Desktop.
using long polling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First go to the head of the stream (in this case we are using the default chat of the chat sample) | |
greg@orc:~/src/EventStore$ curl -i http://127.0.0.1:2113/streams/chat-GeneralChat -H "Accept: application/json" | |
HTTP/1.1 200 OK | |
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS | |
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll | |
Access-Control-Allow-Origin: * | |
Access-Control-Expose-Headers: Location, ES-Position | |
Cache-Control: max-age=0, no-cache, must-revalidate | |
Vary: Accept | |
ETag: "0;-43840953" | |
Content-Type: application/json; charset=utf-8 | |
Server: Mono-HTTPAPI/1.0 | |
Date: Thu, 08 May 2014 10:12:27 GMT | |
Content-Length: 1348 | |
Keep-Alive: timeout=15,max=100 | |
{ | |
"title": "Event stream 'chat-GeneralChat'", | |
"id": "http://127.0.0.1:2113/streams/chat-GeneralChat", | |
"updated": "2014-05-08T07:10:23.666463Z", | |
"streamId": "chat-GeneralChat", | |
"author": { | |
"name": "EventStore" | |
}, | |
"headOfStream": true, | |
"selfUrl": "http://127.0.0.1:2113/streams/chat-GeneralChat", | |
"eTag": "0;248368668", | |
"links": [ | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat", | |
"relation": "self" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/head/backward/20", | |
"relation": "first" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/1/forward/20", | |
"relation": "previous" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/metadata", | |
"relation": "metadata" | |
} | |
], | |
"entries": [ | |
{ | |
"title": "0@chat-GeneralChat", | |
"id": "http://127.0.0.1:2113/streams/chat-GeneralChat/0", | |
"updated": "2014-05-08T07:10:23.666463Z", | |
"author": { | |
"name": "EventStore" | |
}, | |
"summary": "UserJoinedChat", | |
"links": [ | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/0", | |
"relation": "edit" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/0", | |
"relation": "alternate" | |
} | |
] | |
} | |
] | |
} | |
Then grab the previous rel link http://127.0.0.1:2113/streams/chat-GeneralChat/1/forward/20 and try it. Note it brings back an empty feed. | |
greg@orc:~/src/EventStore$ curl -i http://127.0.0.1:2113/streams/chat-GeneralChat/1/forward/20 -H "Accept: application/json" | |
HTTP/1.1 200 OK | |
Access-Control-Allow-Methods: GET, OPTIONS | |
Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll | |
Access-Control-Allow-Origin: * | |
Access-Control-Expose-Headers: Location, ES-Position | |
Cache-Control: max-age=0, no-cache, must-revalidate | |
Vary: Accept | |
ETag: "0;-43840953" | |
Content-Type: application/json; charset=utf-8 | |
Server: Mono-HTTPAPI/1.0 | |
Date: Thu, 08 May 2014 10:13:58 GMT | |
Content-Length: 843 | |
Keep-Alive: timeout=15,max=100 | |
{ | |
"title": "Event stream 'chat-GeneralChat'", | |
"id": "http://127.0.0.1:2113/streams/chat-GeneralChat", | |
"updated": "0001-01-01T00:00:00Z", | |
"streamId": "chat-GeneralChat", | |
"author": { | |
"name": "EventStore" | |
}, | |
"headOfStream": false, | |
"links": [ | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat", | |
"relation": "self" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/head/backward/20", | |
"relation": "first" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/0/forward/20", | |
"relation": "last" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/0/backward/20", | |
"relation": "next" | |
}, | |
{ | |
"uri": "http://127.0.0.1:2113/streams/chat-GeneralChat/metadata", | |
"relation": "metadata" | |
} | |
], | |
"entries": [] | |
} | |
Now try that URI with a long poll header | |
greg@orc:~/src/EventStore$ curl -i http://127.0.0.1:2113/streams/chat-GeneralChat/1/forward/20 -H "Accept: application/json" -H "ES-LongPoll: 30" | |
It will now wait up to 30 seconds for data to appear. Try running then try running and putting a chat into the chat room. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment