Subscribing to event feeds

Listing available feeds

As soon as there exists an event for an aggregate type a feed is created. We can see that a feed for our orderaggregate type is created by listing all available feeds:
cURL
1
curl -i \
2
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
3
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
4
https://api.serialized.io/feeds
Copied!
1
HTTP/1.1 200 OK
2
Content-Type: application/json
3
Vary: Accept-Encoding
4
Content-Length: 19
5
6
{
7
"feeds": [ {
8
"aggregateType": "order",
9
"aggregateCount": 1,
10
"batchCount": 2,
11
"eventCount": 2
12
}
13
}
Copied!

Polling order feed for updates

Let’s take a look at our order feed and list all events for all orders
cURL
1
curl -i \
2
--header "Serialized-Access-Key: <YOUR_ACCESS_KEY>" \
3
--header "Serialized-Secret-Access-Key: <YOUR_SECRET_ACCESS_KEY>" \
4
https://api.serialized.io/feeds/order
Copied!
The response below shows us all events (only two for now), grouped in batches (remember that it’s possible to save more than one event at a time). Each batch has a unique ever-increasing sequence number you can use for tracking which events you have processed. See our sample code for an example of how to poll a feed periodically.
1
HTTP/1.1 200 OK
2
Date: Tue, 15 Aug 2017 14:03:55 GMT
3
Content-Type: application/json
4
Vary: Accept-Encoding
5
Content-Length: 484
6
7
{
8
"entries": [
9
{
10
"sequenceNumber": 1,
11
"aggregateId": "723ecfce-14e9-4889-98d5-a3d0ad54912f",
12
"timestamp": 1504023145574,
13
"feedName": "order",
14
"events":[
15
{
16
"eventId": "127b80b5-4a05-4774-b870-1c9a2e2a27a3",
17
"eventType": "OrderPlacedEvent",
18
"data": {
19
"customerId": "some-test-id-1",
20
"orderAmount": 12345
21
}
22
}
23
]
24
},
25
{
26
"sequenceNumber": 2,
27
"aggregateId": "723ecfce-14e9-4889-98d5-a3d0ad54912f",
28
"timestamp": 1504023255370,
29
"feedName": "order",
30
"events": [
31
{
32
"eventId": "c8b90e06-f3c0-46aa-93a6-c0b281ef3ac5",
33
"eventType": "OrderPaidEvent"
34
}
35
]
36
}
37
],
38
"hasMore": false
39
}
Copied!
The query parameter since can be appended to the URL to reduce the feed to only include “new” events.
1
https://api.serialized.io/feeds/order?since=123
Copied!
The field hasMore in the feed response indicates whether the returned result got limited (because of size) or not. If it’s set to true you could immediately send a new poll request, with an updated since field, to keep on consuming events.